<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.4.0-alpha - src/lapi.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - lapi.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.4.0-alpha</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">593</td>
            <td class="headerCovTableEntry">665</td>
            <td class="headerCovTableEntryMed">89.2 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:19</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: lapi.c $
<span class="lineNum">       3 </span>            : ** Lua API
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #define lapi_c
<span class="lineNum">       8 </span>            : #define LUA_CORE
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #include &quot;lprefix.h&quot;
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #include &lt;limits.h&gt;
<span class="lineNum">      14 </span>            : #include &lt;stdarg.h&gt;
<span class="lineNum">      15 </span>            : #include &lt;string.h&gt;
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      18 </span>            : 
<span class="lineNum">      19 </span>            : #include &quot;lapi.h&quot;
<span class="lineNum">      20 </span>            : #include &quot;ldebug.h&quot;
<span class="lineNum">      21 </span>            : #include &quot;ldo.h&quot;
<span class="lineNum">      22 </span>            : #include &quot;lfunc.h&quot;
<span class="lineNum">      23 </span>            : #include &quot;lgc.h&quot;
<span class="lineNum">      24 </span>            : #include &quot;lmem.h&quot;
<span class="lineNum">      25 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">      26 </span>            : #include &quot;lstate.h&quot;
<span class="lineNum">      27 </span>            : #include &quot;lstring.h&quot;
<span class="lineNum">      28 </span>            : #include &quot;ltable.h&quot;
<span class="lineNum">      29 </span>            : #include &quot;ltm.h&quot;
<span class="lineNum">      30 </span>            : #include &quot;lundump.h&quot;
<span class="lineNum">      31 </span>            : #include &quot;lvm.h&quot;
<span class="lineNum">      32 </span>            : 
<span class="lineNum">      33 </span>            : 
<span class="lineNum">      34 </span>            : 
<span class="lineNum">      35 </span>            : const char lua_ident[] =
<span class="lineNum">      36 </span>            :   &quot;$LuaVersion: &quot; LUA_COPYRIGHT &quot; $&quot;
<span class="lineNum">      37 </span>            :   &quot;$LuaAuthors: &quot; LUA_AUTHORS &quot; $&quot;;
<span class="lineNum">      38 </span>            : 
<span class="lineNum">      39 </span>            : 
<span class="lineNum">      40 </span>            : 
<span class="lineNum">      41 </span>            : /*
<span class="lineNum">      42 </span>            : ** Test for a valid index.
<span class="lineNum">      43 </span>            : ** '!ttisnil(o)' implies 'o != &amp;G(L)-&gt;nilvalue', so it is not needed.
<span class="lineNum">      44 </span>            : ** However, it covers the most common cases in a faster way.
<span class="lineNum">      45 </span>            : */
<span class="lineNum">      46 </span>            : #define isvalid(L, o)   (!ttisnil(o) || o != &amp;G(L)-&gt;nilvalue)
<span class="lineNum">      47 </span>            : 
<span class="lineNum">      48 </span>            : 
<span class="lineNum">      49 </span>            : /* test for pseudo index */
<span class="lineNum">      50 </span>            : #define ispseudo(i)             ((i) &lt;= LUA_REGISTRYINDEX)
<span class="lineNum">      51 </span>            : 
<span class="lineNum">      52 </span>            : /* test for upvalue */
<span class="lineNum">      53 </span>            : #define isupvalue(i)            ((i) &lt; LUA_REGISTRYINDEX)
<span class="lineNum">      54 </span>            : 
<span class="lineNum">      55 </span>            : 
<span class="lineNum">      56 </span><span class="lineCov">    1095151 : static TValue *index2value (lua_State *L, int idx) {</span>
<span class="lineNum">      57 </span><span class="lineCov">    1095151 :   CallInfo *ci = L-&gt;ci;</span>
<span class="lineNum">      58 </span><span class="lineCov">    1095151 :   if (idx &gt; 0) {</span>
<span class="lineNum">      59 </span><span class="lineCov">     670510 :     StkId o = ci-&gt;func + idx;</span>
<span class="lineNum">      60 </span>            :     api_check(L, idx &lt;= L-&gt;ci-&gt;top - (ci-&gt;func + 1), &quot;unacceptable index&quot;);
<span class="lineNum">      61 </span><span class="lineCov">     670510 :     if (o &gt;= L-&gt;top) return &amp;G(L)-&gt;nilvalue;</span>
<span class="lineNum">      62 </span><span class="lineCov">     638749 :     else return s2v(o);</span>
<span class="lineNum">      63 </span>            :   }
<span class="lineNum">      64 </span><span class="lineCov">     424641 :   else if (!ispseudo(idx)) {  /* negative index */</span>
<span class="lineNum">      65 </span>            :     api_check(L, idx != 0 &amp;&amp; -idx &lt;= L-&gt;top - (ci-&gt;func + 1), &quot;invalid index&quot;);
<span class="lineNum">      66 </span><span class="lineCov">     419256 :     return s2v(L-&gt;top + idx);</span>
<span class="lineNum">      67 </span>            :   }
<span class="lineNum">      68 </span><span class="lineCov">       5385 :   else if (idx == LUA_REGISTRYINDEX)</span>
<span class="lineNum">      69 </span><span class="lineCov">       4590 :     return &amp;G(L)-&gt;l_registry;</span>
<span class="lineNum">      70 </span>            :   else {  /* upvalues */
<span class="lineNum">      71 </span><span class="lineCov">        795 :     idx = LUA_REGISTRYINDEX - idx;</span>
<span class="lineNum">      72 </span>            :     api_check(L, idx &lt;= MAXUPVAL + 1, &quot;upvalue index too large&quot;);
<span class="lineNum">      73 </span><span class="lineCov">        795 :     if (ttislcf(s2v(ci-&gt;func)))  /* light C function? */</span>
<span class="lineNum">      74 </span><span class="lineNoCov">          0 :       return &amp;G(L)-&gt;nilvalue;  /* it has no upvalues */</span>
<span class="lineNum">      75 </span>            :     else {
<span class="lineNum">      76 </span><span class="lineCov">        795 :       CClosure *func = clCvalue(s2v(ci-&gt;func));</span>
<span class="lineNum">      77 </span><span class="lineCov">        795 :       return (idx &lt;= func-&gt;nupvalues) ? &amp;func-&gt;upvalue[idx-1] : &amp;G(L)-&gt;nilvalue;</span>
<span class="lineNum">      78 </span>            :     }
<span class="lineNum">      79 </span>            :   }
<span class="lineNum">      80 </span>            : }
<span class="lineNum">      81 </span>            : 
<span class="lineNum">      82 </span>            : 
<span class="lineNum">      83 </span><span class="lineCov">       8757 : static StkId index2stack (lua_State *L, int idx) {</span>
<span class="lineNum">      84 </span><span class="lineCov">       8757 :   CallInfo *ci = L-&gt;ci;</span>
<span class="lineNum">      85 </span><span class="lineCov">       8757 :   if (idx &gt; 0) {</span>
<span class="lineNum">      86 </span><span class="lineCov">       1536 :     StkId o = ci-&gt;func + idx;</span>
<span class="lineNum">      87 </span>            :     api_check(L, o &lt; L-&gt;top, &quot;unacceptable index&quot;);
<span class="lineNum">      88 </span><span class="lineCov">       1536 :     return o;</span>
<span class="lineNum">      89 </span>            :   }
<span class="lineNum">      90 </span>            :   else {    /* non-positive index */
<span class="lineNum">      91 </span>            :     api_check(L, idx != 0 &amp;&amp; -idx &lt;= L-&gt;top - (ci-&gt;func + 1), &quot;invalid index&quot;);
<span class="lineNum">      92 </span>            :     api_check(L, !ispseudo(idx), &quot;invalid index&quot;);
<span class="lineNum">      93 </span><span class="lineCov">       7221 :     return L-&gt;top + idx;</span>
<span class="lineNum">      94 </span>            :   }
<span class="lineNum">      95 </span>            : }
<span class="lineNum">      96 </span>            : 
<span class="lineNum">      97 </span>            : 
<span class="lineNum">      98 </span><span class="lineCov">      14296 : LUA_API int lua_checkstack (lua_State *L, int n) {</span>
<span class="lineNum">      99 </span>            :   int res;
<span class="lineNum">     100 </span><span class="lineCov">      14296 :   CallInfo *ci = L-&gt;ci;</span>
<span class="lineNum">     101 </span>            :   lua_lock(L);
<span class="lineNum">     102 </span>            :   api_check(L, n &gt;= 0, &quot;negative 'n'&quot;);
<span class="lineNum">     103 </span><span class="lineCov">      14296 :   if (L-&gt;stack_last - L-&gt;top &gt; n)  /* stack large enough? */</span>
<span class="lineNum">     104 </span><span class="lineCov">      14296 :     res = 1;  /* yes; check is OK */</span>
<span class="lineNum">     105 </span>            :   else {  /* no; need to grow stack */
<span class="lineNum">     106 </span><span class="lineNoCov">          0 :     int inuse = cast_int(L-&gt;top - L-&gt;stack) + EXTRA_STACK;</span>
<span class="lineNum">     107 </span><span class="lineNoCov">          0 :     if (inuse &gt; LUAI_MAXSTACK - n)  /* can grow without overflow? */</span>
<span class="lineNum">     108 </span><span class="lineNoCov">          0 :       res = 0;  /* no */</span>
<span class="lineNum">     109 </span>            :     else  /* try to grow stack */
<span class="lineNum">     110 </span><span class="lineNoCov">          0 :       res = luaD_growstack(L, n, 0);</span>
<span class="lineNum">     111 </span>            :   }
<span class="lineNum">     112 </span><span class="lineCov">      14296 :   if (res &amp;&amp; ci-&gt;top &lt; L-&gt;top + n)</span>
<span class="lineNum">     113 </span><span class="lineCov">         99 :     ci-&gt;top = L-&gt;top + n;  /* adjust frame top */</span>
<span class="lineNum">     114 </span>            :   lua_unlock(L);
<span class="lineNum">     115 </span><span class="lineCov">      14296 :   return res;</span>
<span class="lineNum">     116 </span>            : }
<span class="lineNum">     117 </span>            : 
<span class="lineNum">     118 </span>            : 
<span class="lineNum">     119 </span><span class="lineCov">      11981 : LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {</span>
<span class="lineNum">     120 </span>            :   int i;
<span class="lineNum">     121 </span><span class="lineCov">      11981 :   if (from == to) return;</span>
<span class="lineNum">     122 </span>            :   lua_lock(to);
<span class="lineNum">     123 </span>            :   api_checknelems(from, n);
<span class="lineNum">     124 </span>            :   api_check(from, G(from) == G(to), &quot;moving among independent states&quot;);
<span class="lineNum">     125 </span>            :   api_check(from, to-&gt;ci-&gt;top - to-&gt;top &gt;= n, &quot;stack overflow&quot;);
<span class="lineNum">     126 </span><span class="lineCov">      11972 :   from-&gt;top -= n;</span>
<span class="lineNum">     127 </span><span class="lineCov">      18111 :   for (i = 0; i &lt; n; i++) {</span>
<span class="lineNum">     128 </span><span class="lineCov">       6139 :     setobjs2s(to, to-&gt;top, from-&gt;top + i);</span>
<span class="lineNum">     129 </span><span class="lineCov">       6139 :     to-&gt;top++;  /* stack already checked by previous 'api_check' */</span>
<span class="lineNum">     130 </span>            :   }
<span class="lineNum">     131 </span>            :   lua_unlock(to);
<span class="lineNum">     132 </span>            : }
<span class="lineNum">     133 </span>            : 
<span class="lineNum">     134 </span>            : 
<span class="lineNum">     135 </span><span class="lineCov">        108 : LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {</span>
<span class="lineNum">     136 </span>            :   lua_CFunction old;
<span class="lineNum">     137 </span>            :   lua_lock(L);
<span class="lineNum">     138 </span><span class="lineCov">        108 :   old = G(L)-&gt;panic;</span>
<span class="lineNum">     139 </span><span class="lineCov">        108 :   G(L)-&gt;panic = panicf;</span>
<span class="lineNum">     140 </span>            :   lua_unlock(L);
<span class="lineNum">     141 </span><span class="lineCov">        108 :   return old;</span>
<span class="lineNum">     142 </span>            : }
<span class="lineNum">     143 </span>            : 
<span class="lineNum">     144 </span>            : 
<span class="lineNum">     145 </span><span class="lineCov">        893 : LUA_API lua_Number lua_version (lua_State *L) {</span>
<span class="lineNum">     146 </span>            :   UNUSED(L);
<span class="lineNum">     147 </span><span class="lineCov">        893 :   return LUA_VERSION_NUM;</span>
<span class="lineNum">     148 </span>            : }
<span class="lineNum">     149 </span>            : 
<span class="lineNum">     150 </span>            : 
<span class="lineNum">     151 </span>            : 
<span class="lineNum">     152 </span>            : /*
<span class="lineNum">     153 </span>            : ** basic stack manipulation
<span class="lineNum">     154 </span>            : */
<span class="lineNum">     155 </span>            : 
<span class="lineNum">     156 </span>            : 
<span class="lineNum">     157 </span>            : /*
<span class="lineNum">     158 </span>            : ** convert an acceptable stack index into an absolute index
<span class="lineNum">     159 </span>            : */
<span class="lineNum">     160 </span><span class="lineCov">       5198 : LUA_API int lua_absindex (lua_State *L, int idx) {</span>
<span class="lineNum">     161 </span><span class="lineCov">        286 :   return (idx &gt; 0 || ispseudo(idx))</span>
<span class="lineNum">     162 </span>            :          ? idx
<span class="lineNum">     163 </span><span class="lineCov">       5484 :          : cast_int(L-&gt;top - L-&gt;ci-&gt;func) + idx;</span>
<span class="lineNum">     164 </span>            : }
<span class="lineNum">     165 </span>            : 
<span class="lineNum">     166 </span>            : 
<span class="lineNum">     167 </span><span class="lineCov">      21702 : LUA_API int lua_gettop (lua_State *L) {</span>
<span class="lineNum">     168 </span><span class="lineCov">      21702 :   return cast_int(L-&gt;top - (L-&gt;ci-&gt;func + 1));</span>
<span class="lineNum">     169 </span>            : }
<span class="lineNum">     170 </span>            : 
<span class="lineNum">     171 </span>            : 
<span class="lineNum">     172 </span><span class="lineCov">     175766 : LUA_API void lua_settop (lua_State *L, int idx) {</span>
<span class="lineNum">     173 </span><span class="lineCov">     175766 :   StkId func = L-&gt;ci-&gt;func;</span>
<span class="lineNum">     174 </span>            :   lua_lock(L);
<span class="lineNum">     175 </span><span class="lineCov">     175766 :   if (idx &gt;= 0) {</span>
<span class="lineNum">     176 </span><span class="lineCov">       6630 :     StkId newtop = (func + 1) + idx;</span>
<span class="lineNum">     177 </span>            :     api_check(L, idx &lt;= L-&gt;stack_last - (func + 1), &quot;new top too large&quot;);
<span class="lineNum">     178 </span><span class="lineCov">      12566 :     while (L-&gt;top &lt; newtop)</span>
<span class="lineNum">     179 </span><span class="lineCov">       5936 :       setnilvalue(s2v(L-&gt;top++));</span>
<span class="lineNum">     180 </span><span class="lineCov">       6630 :     L-&gt;top = newtop;</span>
<span class="lineNum">     181 </span>            :   }
<span class="lineNum">     182 </span>            :   else {
<span class="lineNum">     183 </span>            :     api_check(L, -(idx+1) &lt;= (L-&gt;top - (func + 1)), &quot;invalid new top&quot;);
<span class="lineNum">     184 </span><span class="lineCov">     169136 :     L-&gt;top += idx+1;  /* 'subtract' index (index is negative) */</span>
<span class="lineNum">     185 </span>            :   }
<span class="lineNum">     186 </span><span class="lineCov">     175766 :   luaF_close(L, L-&gt;top, LUA_OK);</span>
<span class="lineNum">     187 </span>            :   lua_unlock(L);
<span class="lineNum">     188 </span><span class="lineCov">     175766 : }</span>
<span class="lineNum">     189 </span>            : 
<span class="lineNum">     190 </span>            : 
<span class="lineNum">     191 </span>            : /*
<span class="lineNum">     192 </span>            : ** Reverse the stack segment from 'from' to 'to'
<span class="lineNum">     193 </span>            : ** (auxiliary to 'lua_rotate')
<span class="lineNum">     194 </span>            : ** Note that we move(copy) only the value inside the stack.
<span class="lineNum">     195 </span>            : ** (We do not move additional fields that may exist.)
<span class="lineNum">     196 </span>            : */
<span class="lineNum">     197 </span><span class="lineCov">      25554 : static void reverse (lua_State *L, StkId from, StkId to) {</span>
<span class="lineNum">     198 </span><span class="lineCov">      33979 :   for (; from &lt; to; from++, to--) {</span>
<span class="lineNum">     199 </span>            :     TValue temp;
<span class="lineNum">     200 </span><span class="lineCov">       8425 :     setobj(L, &amp;temp, s2v(from));</span>
<span class="lineNum">     201 </span><span class="lineCov">       8425 :     setobjs2s(L, from, to);</span>
<span class="lineNum">     202 </span><span class="lineCov">       8425 :     setobj2s(L, to, &amp;temp);</span>
<span class="lineNum">     203 </span>            :   }
<span class="lineNum">     204 </span><span class="lineCov">      25554 : }</span>
<span class="lineNum">     205 </span>            : 
<span class="lineNum">     206 </span>            : 
<span class="lineNum">     207 </span>            : /*
<span class="lineNum">     208 </span>            : ** Let x = AB, where A is a prefix of length 'n'. Then,
<span class="lineNum">     209 </span>            : ** rotate x n == BA. But BA == (A^r . B^r)^r.
<span class="lineNum">     210 </span>            : */
<span class="lineNum">     211 </span><span class="lineCov">       8518 : LUA_API void lua_rotate (lua_State *L, int idx, int n) {</span>
<span class="lineNum">     212 </span>            :   StkId p, t, m;
<span class="lineNum">     213 </span>            :   lua_lock(L);
<span class="lineNum">     214 </span><span class="lineCov">       8518 :   t = L-&gt;top - 1;  /* end of stack segment being rotated */</span>
<span class="lineNum">     215 </span><span class="lineCov">       8518 :   p = index2stack(L, idx);  /* start of segment */</span>
<span class="lineNum">     216 </span>            :   api_check(L, (n &gt;= 0 ? n : -n) &lt;= (t - p + 1), &quot;invalid 'n'&quot;);
<span class="lineNum">     217 </span><span class="lineCov">       8518 :   m = (n &gt;= 0 ? t - n : p - n - 1);  /* end of prefix */</span>
<span class="lineNum">     218 </span><span class="lineCov">       8518 :   reverse(L, p, m);  /* reverse the prefix with length 'n' */</span>
<span class="lineNum">     219 </span><span class="lineCov">       8518 :   reverse(L, m + 1, t);  /* reverse the suffix */</span>
<span class="lineNum">     220 </span><span class="lineCov">       8518 :   reverse(L, p, t);  /* reverse the entire segment */</span>
<span class="lineNum">     221 </span>            :   lua_unlock(L);
<span class="lineNum">     222 </span><span class="lineCov">       8518 : }</span>
<span class="lineNum">     223 </span>            : 
<span class="lineNum">     224 </span>            : 
<span class="lineNum">     225 </span><span class="lineCov">         67 : LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) {</span>
<span class="lineNum">     226 </span>            :   TValue *fr, *to;
<span class="lineNum">     227 </span>            :   lua_lock(L);
<span class="lineNum">     228 </span><span class="lineCov">         67 :   fr = index2value(L, fromidx);</span>
<span class="lineNum">     229 </span><span class="lineCov">         67 :   to = index2value(L, toidx);</span>
<span class="lineNum">     230 </span>            :   api_check(l, isvalid(L, to), &quot;invalid index&quot;);
<span class="lineNum">     231 </span><span class="lineCov">         67 :   setobj(L, to, fr);</span>
<span class="lineNum">     232 </span><span class="lineCov">         67 :   if (isupvalue(toidx))  /* function upvalue? */</span>
<span class="lineNum">     233 </span><span class="lineNoCov">          0 :     luaC_barrier(L, clCvalue(s2v(L-&gt;ci-&gt;func)), fr);</span>
<span class="lineNum">     234 </span>            :   /* LUA_REGISTRYINDEX does not need gc barrier
<span class="lineNum">     235 </span>            :      (collector revisits it before finishing collection) */
<span class="lineNum">     236 </span>            :   lua_unlock(L);
<span class="lineNum">     237 </span><span class="lineCov">         67 : }</span>
<span class="lineNum">     238 </span>            : 
<span class="lineNum">     239 </span>            : 
<span class="lineNum">     240 </span><span class="lineCov">      22785 : LUA_API void lua_pushvalue (lua_State *L, int idx) {</span>
<span class="lineNum">     241 </span>            :   lua_lock(L);
<span class="lineNum">     242 </span><span class="lineCov">      22785 :   setobj2s(L, L-&gt;top, index2value(L, idx));</span>
<span class="lineNum">     243 </span><span class="lineCov">      22785 :   api_incr_top(L);</span>
<span class="lineNum">     244 </span>            :   lua_unlock(L);
<span class="lineNum">     245 </span><span class="lineCov">      22785 : }</span>
<span class="lineNum">     246 </span>            : 
<span class="lineNum">     247 </span>            : 
<span class="lineNum">     248 </span>            : 
<span class="lineNum">     249 </span>            : /*
<span class="lineNum">     250 </span>            : ** access functions (stack -&gt; C)
<span class="lineNum">     251 </span>            : */
<span class="lineNum">     252 </span>            : 
<span class="lineNum">     253 </span>            : 
<span class="lineNum">     254 </span><span class="lineCov">     178619 : LUA_API int lua_type (lua_State *L, int idx) {</span>
<span class="lineNum">     255 </span><span class="lineCov">     178619 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     256 </span><span class="lineCov">     178619 :   return (isvalid(L, o) ? ttype(o) : LUA_TNONE);</span>
<span class="lineNum">     257 </span>            : }
<span class="lineNum">     258 </span>            : 
<span class="lineNum">     259 </span>            : 
<span class="lineNum">     260 </span><span class="lineCov">        240 : LUA_API const char *lua_typename (lua_State *L, int t) {</span>
<span class="lineNum">     261 </span>            :   UNUSED(L);
<span class="lineNum">     262 </span>            :   api_check(L, LUA_TNONE &lt;= t &amp;&amp; t &lt; LUA_NUMTAGS, &quot;invalid tag&quot;);
<span class="lineNum">     263 </span><span class="lineCov">        240 :   return ttypename(t);</span>
<span class="lineNum">     264 </span>            : }
<span class="lineNum">     265 </span>            : 
<span class="lineNum">     266 </span>            : 
<span class="lineNum">     267 </span><span class="lineCov">          2 : LUA_API int lua_iscfunction (lua_State *L, int idx) {</span>
<span class="lineNum">     268 </span><span class="lineCov">          2 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     269 </span><span class="lineCov">          2 :   return (ttislcf(o) || (ttisCclosure(o)));</span>
<span class="lineNum">     270 </span>            : }
<span class="lineNum">     271 </span>            : 
<span class="lineNum">     272 </span>            : 
<span class="lineNum">     273 </span><span class="lineCov">       2170 : LUA_API int lua_isinteger (lua_State *L, int idx) {</span>
<span class="lineNum">     274 </span><span class="lineCov">       2170 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     275 </span><span class="lineCov">       2170 :   return ttisinteger(o);</span>
<span class="lineNum">     276 </span>            : }
<span class="lineNum">     277 </span>            : 
<span class="lineNum">     278 </span>            : 
<span class="lineNum">     279 </span><span class="lineCov">          9 : LUA_API int lua_isnumber (lua_State *L, int idx) {</span>
<span class="lineNum">     280 </span>            :   lua_Number n;
<span class="lineNum">     281 </span><span class="lineCov">          9 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     282 </span><span class="lineCov">          9 :   return tonumber(o, &amp;n);</span>
<span class="lineNum">     283 </span>            : }
<span class="lineNum">     284 </span>            : 
<span class="lineNum">     285 </span>            : 
<span class="lineNum">     286 </span><span class="lineCov">      81245 : LUA_API int lua_isstring (lua_State *L, int idx) {</span>
<span class="lineNum">     287 </span><span class="lineCov">      81245 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     288 </span><span class="lineCov">      81245 :   return (ttisstring(o) || cvt2str(o));</span>
<span class="lineNum">     289 </span>            : }
<span class="lineNum">     290 </span>            : 
<span class="lineNum">     291 </span>            : 
<span class="lineNum">     292 </span><span class="lineNoCov">          0 : LUA_API int lua_isuserdata (lua_State *L, int idx) {</span>
<span class="lineNum">     293 </span><span class="lineNoCov">          0 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     294 </span><span class="lineNoCov">          0 :   return (ttisfulluserdata(o) || ttislightuserdata(o));</span>
<span class="lineNum">     295 </span>            : }
<span class="lineNum">     296 </span>            : 
<span class="lineNum">     297 </span>            : 
<span class="lineNum">     298 </span><span class="lineCov">       3942 : LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {</span>
<span class="lineNum">     299 </span><span class="lineCov">       3942 :   const TValue *o1 = index2value(L, index1);</span>
<span class="lineNum">     300 </span><span class="lineCov">       3942 :   const TValue *o2 = index2value(L, index2);</span>
<span class="lineNum">     301 </span><span class="lineCov">       3942 :   return (isvalid(L, o1) &amp;&amp; isvalid(L, o2)) ? luaV_rawequalobj(o1, o2) : 0;</span>
<span class="lineNum">     302 </span>            : }
<span class="lineNum">     303 </span>            : 
<span class="lineNum">     304 </span>            : 
<span class="lineNum">     305 </span><span class="lineCov">         30 : LUA_API void lua_arith (lua_State *L, int op) {</span>
<span class="lineNum">     306 </span>            :   lua_lock(L);
<span class="lineNum">     307 </span><span class="lineCov">         30 :   if (op != LUA_OPUNM &amp;&amp; op != LUA_OPBNOT)</span>
<span class="lineNum">     308 </span>            :     api_checknelems(L, 2);  /* all other operations expect two operands */
<span class="lineNum">     309 </span>            :   else {  /* for unary operations, add fake 2nd operand */
<span class="lineNum">     310 </span>            :     api_checknelems(L, 1);
<span class="lineNum">     311 </span><span class="lineCov">          1 :     setobjs2s(L, L-&gt;top, L-&gt;top - 1);</span>
<span class="lineNum">     312 </span><span class="lineCov">          1 :     api_incr_top(L);</span>
<span class="lineNum">     313 </span>            :   }
<span class="lineNum">     314 </span>            :   /* first operand at top - 2, second at top - 1; result go to top - 2 */
<span class="lineNum">     315 </span><span class="lineCov">         30 :   luaO_arith(L, op, s2v(L-&gt;top - 2), s2v(L-&gt;top - 1), L-&gt;top - 2);</span>
<span class="lineNum">     316 </span><span class="lineCov">         30 :   L-&gt;top--;  /* remove second operand */</span>
<span class="lineNum">     317 </span>            :   lua_unlock(L);
<span class="lineNum">     318 </span><span class="lineCov">         30 : }</span>
<span class="lineNum">     319 </span>            : 
<span class="lineNum">     320 </span>            : 
<span class="lineNum">     321 </span><span class="lineCov">      91624 : LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {</span>
<span class="lineNum">     322 </span>            :   const TValue *o1;
<span class="lineNum">     323 </span>            :   const TValue *o2;
<span class="lineNum">     324 </span><span class="lineCov">      91624 :   int i = 0;</span>
<span class="lineNum">     325 </span>            :   lua_lock(L);  /* may call tag method */
<span class="lineNum">     326 </span><span class="lineCov">      91624 :   o1 = index2value(L, index1);</span>
<span class="lineNum">     327 </span><span class="lineCov">      91624 :   o2 = index2value(L, index2);</span>
<span class="lineNum">     328 </span><span class="lineCov">      91624 :   if (isvalid(L, o1) &amp;&amp; isvalid(L, o2)) {</span>
<span class="lineNum">     329 </span><span class="lineCov">      91624 :     switch (op) {</span>
<span class="lineNum">     330 </span><span class="lineCov">          1 :       case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break;</span>
<span class="lineNum">     331 </span><span class="lineCov">      91623 :       case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;</span>
<span class="lineNum">     332 </span><span class="lineNoCov">          0 :       case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;</span>
<span class="lineNum">     333 </span><span class="lineNoCov">          0 :       default: api_check(L, 0, &quot;invalid option&quot;);</span>
<span class="lineNum">     334 </span>            :     }
<span class="lineNum">     335 </span>            :   }
<span class="lineNum">     336 </span>            :   lua_unlock(L);
<span class="lineNum">     337 </span><span class="lineCov">      91624 :   return i;</span>
<span class="lineNum">     338 </span>            : }
<span class="lineNum">     339 </span>            : 
<span class="lineNum">     340 </span>            : 
<span class="lineNum">     341 </span><span class="lineCov">        102 : LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) {</span>
<span class="lineNum">     342 </span><span class="lineCov">        102 :   size_t sz = luaO_str2num(s, s2v(L-&gt;top));</span>
<span class="lineNum">     343 </span><span class="lineCov">        102 :   if (sz != 0)</span>
<span class="lineNum">     344 </span><span class="lineCov">         80 :     api_incr_top(L);</span>
<span class="lineNum">     345 </span><span class="lineCov">        102 :   return sz;</span>
<span class="lineNum">     346 </span>            : }
<span class="lineNum">     347 </span>            : 
<span class="lineNum">     348 </span>            : 
<span class="lineNum">     349 </span><span class="lineCov">        107 : LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) {</span>
<span class="lineNum">     350 </span>            :   lua_Number n;
<span class="lineNum">     351 </span><span class="lineCov">        107 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     352 </span><span class="lineCov">        107 :   int isnum = tonumber(o, &amp;n);</span>
<span class="lineNum">     353 </span><span class="lineCov">        107 :   if (!isnum)</span>
<span class="lineNum">     354 </span><span class="lineNoCov">          0 :     n = 0;  /* call to 'tonumber' may change 'n' even if it fails */</span>
<span class="lineNum">     355 </span><span class="lineCov">        107 :   if (pisnum) *pisnum = isnum;</span>
<span class="lineNum">     356 </span><span class="lineCov">        107 :   return n;</span>
<span class="lineNum">     357 </span>            : }
<span class="lineNum">     358 </span>            : 
<span class="lineNum">     359 </span>            : 
<span class="lineNum">     360 </span><span class="lineCov">      79955 : LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) {</span>
<span class="lineNum">     361 </span>            :   lua_Integer res;
<span class="lineNum">     362 </span><span class="lineCov">      79955 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     363 </span><span class="lineCov">      79955 :   int isnum = tointeger(o, &amp;res);</span>
<span class="lineNum">     364 </span><span class="lineCov">      79955 :   if (!isnum)</span>
<span class="lineNum">     365 </span><span class="lineCov">        135 :     res = 0;  /* call to 'tointeger' may change 'n' even if it fails */</span>
<span class="lineNum">     366 </span><span class="lineCov">      79955 :   if (pisnum) *pisnum = isnum;</span>
<span class="lineNum">     367 </span><span class="lineCov">      79955 :   return res;</span>
<span class="lineNum">     368 </span>            : }
<span class="lineNum">     369 </span>            : 
<span class="lineNum">     370 </span>            : 
<span class="lineNum">     371 </span><span class="lineCov">       7415 : LUA_API int lua_toboolean (lua_State *L, int idx) {</span>
<span class="lineNum">     372 </span><span class="lineCov">       7415 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     373 </span><span class="lineCov">       7415 :   return !l_isfalse(o);</span>
<span class="lineNum">     374 </span>            : }
<span class="lineNum">     375 </span>            : 
<span class="lineNum">     376 </span>            : 
<span class="lineNum">     377 </span><span class="lineCov">     108640 : LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {</span>
<span class="lineNum">     378 </span><span class="lineCov">     108640 :   TValue *o = index2value(L, idx);</span>
<span class="lineNum">     379 </span><span class="lineCov">     108640 :   if (!ttisstring(o)) {</span>
<span class="lineNum">     380 </span><span class="lineCov">         30 :     if (!cvt2str(o)) {  /* not convertible? */</span>
<span class="lineNum">     381 </span><span class="lineCov">         29 :       if (len != NULL) *len = 0;</span>
<span class="lineNum">     382 </span><span class="lineCov">         29 :       return NULL;</span>
<span class="lineNum">     383 </span>            :     }
<span class="lineNum">     384 </span>            :     lua_lock(L);  /* 'luaO_tostring' may create a new string */
<span class="lineNum">     385 </span><span class="lineCov">          1 :     luaO_tostring(L, o);</span>
<span class="lineNum">     386 </span><span class="lineCov">          1 :     luaC_checkGC(L);</span>
<span class="lineNum">     387 </span><span class="lineCov">          1 :     o = index2value(L, idx);  /* previous call may reallocate the stack */</span>
<span class="lineNum">     388 </span>            :     lua_unlock(L);
<span class="lineNum">     389 </span>            :   }
<span class="lineNum">     390 </span><span class="lineCov">     108611 :   if (len != NULL)</span>
<span class="lineNum">     391 </span><span class="lineCov">     104023 :     *len = vslen(o);</span>
<span class="lineNum">     392 </span><span class="lineCov">     108611 :   return svalue(o);</span>
<span class="lineNum">     393 </span>            : }
<span class="lineNum">     394 </span>            : 
<span class="lineNum">     395 </span>            : 
<span class="lineNum">     396 </span><span class="lineCov">        128 : LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) {</span>
<span class="lineNum">     397 </span><span class="lineCov">        128 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     398 </span><span class="lineCov">        128 :   switch (ttypetag(o)) {</span>
<span class="lineNum">     399 </span><span class="lineCov">         19 :     case LUA_TSHRSTR: return tsvalue(o)-&gt;shrlen;</span>
<span class="lineNum">     400 </span><span class="lineNoCov">          0 :     case LUA_TLNGSTR: return tsvalue(o)-&gt;u.lnglen;</span>
<span class="lineNum">     401 </span><span class="lineNoCov">          0 :     case LUA_TUSERDATA: return uvalue(o)-&gt;len;</span>
<span class="lineNum">     402 </span><span class="lineCov">        109 :     case LUA_TTABLE: return luaH_getn(hvalue(o));</span>
<span class="lineNum">     403 </span><span class="lineNoCov">          0 :     default: return 0;</span>
<span class="lineNum">     404 </span>            :   }
<span class="lineNum">     405 </span>            : }
<span class="lineNum">     406 </span>            : 
<span class="lineNum">     407 </span>            : 
<span class="lineNum">     408 </span><span class="lineNoCov">          0 : LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {</span>
<span class="lineNum">     409 </span><span class="lineNoCov">          0 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     410 </span><span class="lineNoCov">          0 :   if (ttislcf(o)) return fvalue(o);</span>
<span class="lineNum">     411 </span><span class="lineNoCov">          0 :   else if (ttisCclosure(o))</span>
<span class="lineNum">     412 </span><span class="lineNoCov">          0 :     return clCvalue(o)-&gt;f;</span>
<span class="lineNum">     413 </span><span class="lineNoCov">          0 :   else return NULL;  /* not a C function */</span>
<span class="lineNum">     414 </span>            : }
<span class="lineNum">     415 </span>            : 
<span class="lineNum">     416 </span>            : 
<span class="lineNum">     417 </span><span class="lineCov">       1689 : static void *touserdata (const TValue *o) {</span>
<span class="lineNum">     418 </span><span class="lineCov">       1689 :   switch (ttype(o)) {</span>
<span class="lineNum">     419 </span><span class="lineCov">       1578 :     case LUA_TUSERDATA: return getudatamem(uvalue(o));</span>
<span class="lineNum">     420 </span><span class="lineCov">        108 :     case LUA_TLIGHTUSERDATA: return pvalue(o);</span>
<span class="lineNum">     421 </span><span class="lineCov">          3 :     default: return NULL;</span>
<span class="lineNum">     422 </span>            :   }
<span class="lineNum">     423 </span>            : }
<span class="lineNum">     424 </span>            : 
<span class="lineNum">     425 </span>            : 
<span class="lineNum">     426 </span><span class="lineCov">       1689 : LUA_API void *lua_touserdata (lua_State *L, int idx) {</span>
<span class="lineNum">     427 </span><span class="lineCov">       1689 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     428 </span><span class="lineCov">       1689 :   return touserdata(o);</span>
<span class="lineNum">     429 </span>            : }
<span class="lineNum">     430 </span>            : 
<span class="lineNum">     431 </span>            : 
<span class="lineNum">     432 </span><span class="lineCov">       5983 : LUA_API lua_State *lua_tothread (lua_State *L, int idx) {</span>
<span class="lineNum">     433 </span><span class="lineCov">       5983 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     434 </span><span class="lineCov">       5983 :   return (!ttisthread(o)) ? NULL : thvalue(o);</span>
<span class="lineNum">     435 </span>            : }
<span class="lineNum">     436 </span>            : 
<span class="lineNum">     437 </span>            : 
<span class="lineNum">     438 </span>            : /*
<span class="lineNum">     439 </span>            : ** Returns a pointer to the internal representation of an object.
<span class="lineNum">     440 </span>            : ** Note that ANSI C does not allow the conversion of a pointer to
<span class="lineNum">     441 </span>            : ** function to a 'void*', so the conversion here goes through
<span class="lineNum">     442 </span>            : ** a 'size_t'. (As the returned pointer is only informative, this
<span class="lineNum">     443 </span>            : ** conversion should not be a problem.)
<span class="lineNum">     444 </span>            : */
<span class="lineNum">     445 </span><span class="lineCov">          7 : LUA_API const void *lua_topointer (lua_State *L, int idx) {</span>
<span class="lineNum">     446 </span><span class="lineCov">          7 :   const TValue *o = index2value(L, idx);</span>
<span class="lineNum">     447 </span><span class="lineCov">          7 :   switch (ttypetag(o)) {</span>
<span class="lineNum">     448 </span><span class="lineCov">          2 :     case LUA_TLCF: return cast_voidp(cast_sizet(fvalue(o)));</span>
<span class="lineNum">     449 </span><span class="lineNoCov">          0 :     case LUA_TUSERDATA: case LUA_TLIGHTUSERDATA:</span>
<span class="lineNum">     450 </span><span class="lineNoCov">          0 :       return touserdata(o);</span>
<span class="lineNum">     451 </span><span class="lineCov">          5 :     default: {</span>
<span class="lineNum">     452 </span><span class="lineCov">          5 :       if (iscollectable(o))</span>
<span class="lineNum">     453 </span><span class="lineCov">          5 :         return gcvalue(o);</span>
<span class="lineNum">     454 </span>            :       else
<span class="lineNum">     455 </span><span class="lineNoCov">          0 :         return NULL;</span>
<span class="lineNum">     456 </span>            :     }
<span class="lineNum">     457 </span>            :   }
<span class="lineNum">     458 </span>            : }
<span class="lineNum">     459 </span>            : 
<span class="lineNum">     460 </span>            : 
<span class="lineNum">     461 </span>            : 
<span class="lineNum">     462 </span>            : /*
<span class="lineNum">     463 </span>            : ** push functions (C -&gt; stack)
<span class="lineNum">     464 </span>            : */
<span class="lineNum">     465 </span>            : 
<span class="lineNum">     466 </span>            : 
<span class="lineNum">     467 </span><span class="lineCov">        906 : LUA_API void lua_pushnil (lua_State *L) {</span>
<span class="lineNum">     468 </span>            :   lua_lock(L);
<span class="lineNum">     469 </span><span class="lineCov">        906 :   setnilvalue(s2v(L-&gt;top));</span>
<span class="lineNum">     470 </span><span class="lineCov">        906 :   api_incr_top(L);</span>
<span class="lineNum">     471 </span>            :   lua_unlock(L);
<span class="lineNum">     472 </span><span class="lineCov">        906 : }</span>
<span class="lineNum">     473 </span>            : 
<span class="lineNum">     474 </span>            : 
<span class="lineNum">     475 </span><span class="lineCov">        222 : LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {</span>
<span class="lineNum">     476 </span>            :   lua_lock(L);
<span class="lineNum">     477 </span><span class="lineCov">        222 :   setfltvalue(s2v(L-&gt;top), n);</span>
<span class="lineNum">     478 </span><span class="lineCov">        222 :   api_incr_top(L);</span>
<span class="lineNum">     479 </span>            :   lua_unlock(L);
<span class="lineNum">     480 </span><span class="lineCov">        222 : }</span>
<span class="lineNum">     481 </span>            : 
<span class="lineNum">     482 </span>            : 
<span class="lineNum">     483 </span><span class="lineCov">      53078 : LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {</span>
<span class="lineNum">     484 </span>            :   lua_lock(L);
<span class="lineNum">     485 </span><span class="lineCov">      53078 :   setivalue(s2v(L-&gt;top), n);</span>
<span class="lineNum">     486 </span><span class="lineCov">      53078 :   api_incr_top(L);</span>
<span class="lineNum">     487 </span>            :   lua_unlock(L);
<span class="lineNum">     488 </span><span class="lineCov">      53078 : }</span>
<span class="lineNum">     489 </span>            : 
<span class="lineNum">     490 </span>            : 
<span class="lineNum">     491 </span>            : /*
<span class="lineNum">     492 </span>            : ** Pushes on the stack a string with given length. Avoid using 's' when
<span class="lineNum">     493 </span>            : ** 'len' == 0 (as 's' can be NULL in that case), due to later use of
<span class="lineNum">     494 </span>            : ** 'memcmp' and 'memcpy'.
<span class="lineNum">     495 </span>            : */
<span class="lineNum">     496 </span><span class="lineCov">      19937 : LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {</span>
<span class="lineNum">     497 </span>            :   TString *ts;
<span class="lineNum">     498 </span>            :   lua_lock(L);
<span class="lineNum">     499 </span><span class="lineCov">      19937 :   ts = (len == 0) ? luaS_new(L, &quot;&quot;) : luaS_newlstr(L, s, len);</span>
<span class="lineNum">     500 </span><span class="lineCov">      19937 :   setsvalue2s(L, L-&gt;top, ts);</span>
<span class="lineNum">     501 </span><span class="lineCov">      19937 :   api_incr_top(L);</span>
<span class="lineNum">     502 </span><span class="lineCov">      19937 :   luaC_checkGC(L);</span>
<span class="lineNum">     503 </span>            :   lua_unlock(L);
<span class="lineNum">     504 </span><span class="lineCov">      19937 :   return getstr(ts);</span>
<span class="lineNum">     505 </span>            : }
<span class="lineNum">     506 </span>            : 
<span class="lineNum">     507 </span>            : 
<span class="lineNum">     508 </span><span class="lineCov">       6047 : LUA_API const char *lua_pushstring (lua_State *L, const char *s) {</span>
<span class="lineNum">     509 </span>            :   lua_lock(L);
<span class="lineNum">     510 </span><span class="lineCov">       6047 :   if (s == NULL)</span>
<span class="lineNum">     511 </span><span class="lineCov">          5 :     setnilvalue(s2v(L-&gt;top));</span>
<span class="lineNum">     512 </span>            :   else {
<span class="lineNum">     513 </span>            :     TString *ts;
<span class="lineNum">     514 </span><span class="lineCov">       6042 :     ts = luaS_new(L, s);</span>
<span class="lineNum">     515 </span><span class="lineCov">       6042 :     setsvalue2s(L, L-&gt;top, ts);</span>
<span class="lineNum">     516 </span><span class="lineCov">       6042 :     s = getstr(ts);  /* internal copy's address */</span>
<span class="lineNum">     517 </span>            :   }
<span class="lineNum">     518 </span><span class="lineCov">       6047 :   api_incr_top(L);</span>
<span class="lineNum">     519 </span><span class="lineCov">       6047 :   luaC_checkGC(L);</span>
<span class="lineNum">     520 </span>            :   lua_unlock(L);
<span class="lineNum">     521 </span><span class="lineCov">       6047 :   return s;</span>
<span class="lineNum">     522 </span>            : }
<span class="lineNum">     523 </span>            : 
<span class="lineNum">     524 </span>            : 
<span class="lineNum">     525 </span><span class="lineCov">        181 : LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,</span>
<span class="lineNum">     526 </span>            :                                       va_list argp) {
<span class="lineNum">     527 </span>            :   const char *ret;
<span class="lineNum">     528 </span>            :   lua_lock(L);
<span class="lineNum">     529 </span><span class="lineCov">        181 :   ret = luaO_pushvfstring(L, fmt, argp);</span>
<span class="lineNum">     530 </span><span class="lineCov">        181 :   luaC_checkGC(L);</span>
<span class="lineNum">     531 </span>            :   lua_unlock(L);
<span class="lineNum">     532 </span><span class="lineCov">        181 :   return ret;</span>
<span class="lineNum">     533 </span>            : }
<span class="lineNum">     534 </span>            : 
<span class="lineNum">     535 </span>            : 
<span class="lineNum">     536 </span><span class="lineCov">       2914 : LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {</span>
<span class="lineNum">     537 </span>            :   const char *ret;
<span class="lineNum">     538 </span>            :   va_list argp;
<span class="lineNum">     539 </span>            :   lua_lock(L);
<span class="lineNum">     540 </span><span class="lineCov">       2914 :   va_start(argp, fmt);</span>
<span class="lineNum">     541 </span><span class="lineCov">       2914 :   ret = luaO_pushvfstring(L, fmt, argp);</span>
<span class="lineNum">     542 </span><span class="lineCov">       2914 :   va_end(argp);</span>
<span class="lineNum">     543 </span><span class="lineCov">       2914 :   luaC_checkGC(L);</span>
<span class="lineNum">     544 </span>            :   lua_unlock(L);
<span class="lineNum">     545 </span><span class="lineCov">       2914 :   return ret;</span>
<span class="lineNum">     546 </span>            : }
<span class="lineNum">     547 </span>            : 
<span class="lineNum">     548 </span>            : 
<span class="lineNum">     549 </span><span class="lineCov">      20976 : LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {</span>
<span class="lineNum">     550 </span>            :   lua_lock(L);
<span class="lineNum">     551 </span><span class="lineCov">      20976 :   if (n == 0) {</span>
<span class="lineNum">     552 </span><span class="lineCov">      20333 :     setfvalue(s2v(L-&gt;top), fn);</span>
<span class="lineNum">     553 </span><span class="lineCov">      20333 :     api_incr_top(L);</span>
<span class="lineNum">     554 </span>            :   }
<span class="lineNum">     555 </span>            :   else {
<span class="lineNum">     556 </span>            :     CClosure *cl;
<span class="lineNum">     557 </span>            :     api_checknelems(L, n);
<span class="lineNum">     558 </span>            :     api_check(L, n &lt;= MAXUPVAL, &quot;upvalue index too large&quot;);
<span class="lineNum">     559 </span><span class="lineCov">        643 :     cl = luaF_newCclosure(L, n);</span>
<span class="lineNum">     560 </span><span class="lineCov">        643 :     cl-&gt;f = fn;</span>
<span class="lineNum">     561 </span><span class="lineCov">        643 :     L-&gt;top -= n;</span>
<span class="lineNum">     562 </span><span class="lineCov">       1313 :     while (n--) {</span>
<span class="lineNum">     563 </span><span class="lineCov">        670 :       setobj2n(L, &amp;cl-&gt;upvalue[n], s2v(L-&gt;top + n));</span>
<span class="lineNum">     564 </span>            :       /* does not need barrier because closure is white */
<span class="lineNum">     565 </span>            :     }
<span class="lineNum">     566 </span><span class="lineCov">        643 :     setclCvalue(L, s2v(L-&gt;top), cl);</span>
<span class="lineNum">     567 </span><span class="lineCov">        643 :     api_incr_top(L);</span>
<span class="lineNum">     568 </span><span class="lineCov">        643 :     luaC_checkGC(L);</span>
<span class="lineNum">     569 </span>            :   }
<span class="lineNum">     570 </span>            :   lua_unlock(L);
<span class="lineNum">     571 </span><span class="lineCov">      20976 : }</span>
<span class="lineNum">     572 </span>            : 
<span class="lineNum">     573 </span>            : 
<span class="lineNum">     574 </span><span class="lineCov">       8689 : LUA_API void lua_pushboolean (lua_State *L, int b) {</span>
<span class="lineNum">     575 </span>            :   lua_lock(L);
<span class="lineNum">     576 </span><span class="lineCov">       8689 :   setbvalue(s2v(L-&gt;top), (b != 0));  /* ensure that true is 1 */</span>
<span class="lineNum">     577 </span><span class="lineCov">       8689 :   api_incr_top(L);</span>
<span class="lineNum">     578 </span>            :   lua_unlock(L);
<span class="lineNum">     579 </span><span class="lineCov">       8689 : }</span>
<span class="lineNum">     580 </span>            : 
<span class="lineNum">     581 </span>            : 
<span class="lineNum">     582 </span><span class="lineCov">        109 : LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {</span>
<span class="lineNum">     583 </span>            :   lua_lock(L);
<span class="lineNum">     584 </span><span class="lineCov">        109 :   setpvalue(s2v(L-&gt;top), p);</span>
<span class="lineNum">     585 </span><span class="lineCov">        109 :   api_incr_top(L);</span>
<span class="lineNum">     586 </span>            :   lua_unlock(L);
<span class="lineNum">     587 </span><span class="lineCov">        109 : }</span>
<span class="lineNum">     588 </span>            : 
<span class="lineNum">     589 </span>            : 
<span class="lineNum">     590 </span><span class="lineCov">        213 : LUA_API int lua_pushthread (lua_State *L) {</span>
<span class="lineNum">     591 </span>            :   lua_lock(L);
<span class="lineNum">     592 </span><span class="lineCov">        213 :   setthvalue(L, s2v(L-&gt;top), L);</span>
<span class="lineNum">     593 </span><span class="lineCov">        213 :   api_incr_top(L);</span>
<span class="lineNum">     594 </span>            :   lua_unlock(L);
<span class="lineNum">     595 </span><span class="lineCov">        213 :   return (G(L)-&gt;mainthread == L);</span>
<span class="lineNum">     596 </span>            : }
<span class="lineNum">     597 </span>            : 
<span class="lineNum">     598 </span>            : 
<span class="lineNum">     599 </span>            : 
<span class="lineNum">     600 </span>            : /*
<span class="lineNum">     601 </span>            : ** get functions (Lua -&gt; stack)
<span class="lineNum">     602 </span>            : */
<span class="lineNum">     603 </span>            : 
<span class="lineNum">     604 </span>            : 
<span class="lineNum">     605 </span><span class="lineCov">       5147 : static int auxgetstr (lua_State *L, const TValue *t, const char *k) {</span>
<span class="lineNum">     606 </span>            :   const TValue *slot;
<span class="lineNum">     607 </span><span class="lineCov">       5147 :   TString *str = luaS_new(L, k);</span>
<span class="lineNum">     608 </span><span class="lineCov">       5147 :   if (luaV_fastget(L, t, str, slot, luaH_getstr)) {</span>
<span class="lineNum">     609 </span><span class="lineCov">       3553 :     setobj2s(L, L-&gt;top, slot);</span>
<span class="lineNum">     610 </span><span class="lineCov">       3553 :     api_incr_top(L);</span>
<span class="lineNum">     611 </span>            :   }
<span class="lineNum">     612 </span>            :   else {
<span class="lineNum">     613 </span><span class="lineCov">       1594 :     setsvalue2s(L, L-&gt;top, str);</span>
<span class="lineNum">     614 </span><span class="lineCov">       1594 :     api_incr_top(L);</span>
<span class="lineNum">     615 </span><span class="lineCov">       1594 :     luaV_finishget(L, t, s2v(L-&gt;top - 1), L-&gt;top - 1, slot);</span>
<span class="lineNum">     616 </span>            :   }
<span class="lineNum">     617 </span>            :   lua_unlock(L);
<span class="lineNum">     618 </span><span class="lineCov">       5147 :   return ttype(s2v(L-&gt;top - 1));</span>
<span class="lineNum">     619 </span>            : }
<span class="lineNum">     620 </span>            : 
<span class="lineNum">     621 </span>            : 
<span class="lineNum">     622 </span><span class="lineCov">        110 : LUA_API int lua_getglobal (lua_State *L, const char *name) {</span>
<span class="lineNum">     623 </span><span class="lineCov">        110 :   Table *reg = hvalue(&amp;G(L)-&gt;l_registry);</span>
<span class="lineNum">     624 </span>            :   lua_lock(L);
<span class="lineNum">     625 </span><span class="lineCov">        110 :   return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);</span>
<span class="lineNum">     626 </span>            : }
<span class="lineNum">     627 </span>            : 
<span class="lineNum">     628 </span>            : 
<span class="lineNum">     629 </span><span class="lineCov">          8 : LUA_API int lua_gettable (lua_State *L, int idx) {</span>
<span class="lineNum">     630 </span>            :   const TValue *slot;
<span class="lineNum">     631 </span>            :   TValue *t;
<span class="lineNum">     632 </span>            :   lua_lock(L);
<span class="lineNum">     633 </span><span class="lineCov">          8 :   t = index2value(L, idx);</span>
<span class="lineNum">     634 </span><span class="lineCov">          8 :   if (luaV_fastget(L, t, s2v(L-&gt;top - 1), slot, luaH_get)) {</span>
<span class="lineNum">     635 </span><span class="lineCov">          7 :     setobj2s(L, L-&gt;top - 1, slot);</span>
<span class="lineNum">     636 </span>            :   }
<span class="lineNum">     637 </span>            :   else
<span class="lineNum">     638 </span><span class="lineCov">          1 :     luaV_finishget(L, t, s2v(L-&gt;top - 1), L-&gt;top - 1, slot);</span>
<span class="lineNum">     639 </span>            :   lua_unlock(L);
<span class="lineNum">     640 </span><span class="lineCov">          8 :   return ttype(s2v(L-&gt;top - 1));</span>
<span class="lineNum">     641 </span>            : }
<span class="lineNum">     642 </span>            : 
<span class="lineNum">     643 </span>            : 
<span class="lineNum">     644 </span><span class="lineCov">       5037 : LUA_API int lua_getfield (lua_State *L, int idx, const char *k) {</span>
<span class="lineNum">     645 </span>            :   lua_lock(L);
<span class="lineNum">     646 </span><span class="lineCov">       5037 :   return auxgetstr(L, index2value(L, idx), k);</span>
<span class="lineNum">     647 </span>            : }
<span class="lineNum">     648 </span>            : 
<span class="lineNum">     649 </span>            : 
<span class="lineNum">     650 </span><span class="lineCov">     273131 : LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {</span>
<span class="lineNum">     651 </span>            :   TValue *t;
<span class="lineNum">     652 </span>            :   const TValue *slot;
<span class="lineNum">     653 </span>            :   lua_lock(L);
<span class="lineNum">     654 </span><span class="lineCov">     273131 :   t = index2value(L, idx);</span>
<span class="lineNum">     655 </span><span class="lineCov">     273131 :   if (luaV_fastgeti(L, t, n, slot)) {</span>
<span class="lineNum">     656 </span><span class="lineCov">     267203 :     setobj2s(L, L-&gt;top, slot);</span>
<span class="lineNum">     657 </span>            :   }
<span class="lineNum">     658 </span>            :   else {
<span class="lineNum">     659 </span>            :     TValue aux;
<span class="lineNum">     660 </span><span class="lineCov">       5928 :     setivalue(&amp;aux, n);</span>
<span class="lineNum">     661 </span><span class="lineCov">       5928 :     luaV_finishget(L, t, &amp;aux, L-&gt;top, slot);</span>
<span class="lineNum">     662 </span>            :   }
<span class="lineNum">     663 </span><span class="lineCov">     273131 :   api_incr_top(L);</span>
<span class="lineNum">     664 </span>            :   lua_unlock(L);
<span class="lineNum">     665 </span><span class="lineCov">     273131 :   return ttype(s2v(L-&gt;top - 1));</span>
<span class="lineNum">     666 </span>            : }
<span class="lineNum">     667 </span>            : 
<span class="lineNum">     668 </span>            : 
<span class="lineNum">     669 </span><span class="lineCov">       3985 : static int finishrawget (lua_State *L, const TValue *val) {</span>
<span class="lineNum">     670 </span><span class="lineCov">       3985 :   if (isempty(val))  /* avoid copying empty items to the stack */</span>
<span class="lineNum">     671 </span><span class="lineCov">       2948 :     setnilvalue(s2v(L-&gt;top));</span>
<span class="lineNum">     672 </span>            :   else
<span class="lineNum">     673 </span><span class="lineCov">       1037 :     setobj2s(L, L-&gt;top, val);</span>
<span class="lineNum">     674 </span><span class="lineCov">       3985 :   api_incr_top(L);</span>
<span class="lineNum">     675 </span>            :   lua_unlock(L);
<span class="lineNum">     676 </span><span class="lineCov">       3985 :   return ttype(s2v(L-&gt;top - 1));</span>
<span class="lineNum">     677 </span>            : }
<span class="lineNum">     678 </span>            : 
<span class="lineNum">     679 </span>            : 
<span class="lineNum">     680 </span><span class="lineCov">       7644 : static Table *gettable (lua_State *L, int idx) {</span>
<span class="lineNum">     681 </span><span class="lineCov">       7644 :   TValue *t = index2value(L, idx);</span>
<span class="lineNum">     682 </span>            :   api_check(L, ttistable(t), &quot;table expected&quot;);
<span class="lineNum">     683 </span><span class="lineCov">       7644 :   return hvalue(t);</span>
<span class="lineNum">     684 </span>            : }
<span class="lineNum">     685 </span>            : 
<span class="lineNum">     686 </span>            : 
<span class="lineNum">     687 </span><span class="lineCov">       3051 : LUA_API int lua_rawget (lua_State *L, int idx) {</span>
<span class="lineNum">     688 </span>            :   Table *t;
<span class="lineNum">     689 </span>            :   const TValue *val;
<span class="lineNum">     690 </span>            :   lua_lock(L);
<span class="lineNum">     691 </span>            :   api_checknelems(L, 1);
<span class="lineNum">     692 </span><span class="lineCov">       3051 :   t = gettable(L, idx);</span>
<span class="lineNum">     693 </span><span class="lineCov">       3051 :   val = luaH_get(t, s2v(L-&gt;top - 1));</span>
<span class="lineNum">     694 </span><span class="lineCov">       3051 :   L-&gt;top--;  /* remove key */</span>
<span class="lineNum">     695 </span><span class="lineCov">       3051 :   return finishrawget(L, val);</span>
<span class="lineNum">     696 </span>            : }
<span class="lineNum">     697 </span>            : 
<span class="lineNum">     698 </span>            : 
<span class="lineNum">     699 </span><span class="lineCov">        721 : LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {</span>
<span class="lineNum">     700 </span>            :   Table *t;
<span class="lineNum">     701 </span>            :   lua_lock(L);
<span class="lineNum">     702 </span><span class="lineCov">        721 :   t = gettable(L, idx);</span>
<span class="lineNum">     703 </span><span class="lineCov">        721 :   return finishrawget(L, luaH_getint(t, n));</span>
<span class="lineNum">     704 </span>            : }
<span class="lineNum">     705 </span>            : 
<span class="lineNum">     706 </span>            : 
<span class="lineNum">     707 </span><span class="lineCov">        213 : LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {</span>
<span class="lineNum">     708 </span>            :   Table *t;
<span class="lineNum">     709 </span>            :   TValue k;
<span class="lineNum">     710 </span>            :   lua_lock(L);
<span class="lineNum">     711 </span><span class="lineCov">        213 :   t = gettable(L, idx);</span>
<span class="lineNum">     712 </span><span class="lineCov">        213 :   setpvalue(&amp;k, cast_voidp(p));</span>
<span class="lineNum">     713 </span><span class="lineCov">        213 :   return finishrawget(L, luaH_get(t, &amp;k));</span>
<span class="lineNum">     714 </span>            : }
<span class="lineNum">     715 </span>            : 
<span class="lineNum">     716 </span>            : 
<span class="lineNum">     717 </span><span class="lineCov">       1521 : LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {</span>
<span class="lineNum">     718 </span>            :   Table *t;
<span class="lineNum">     719 </span>            :   lua_lock(L);
<span class="lineNum">     720 </span><span class="lineCov">       1521 :   t = luaH_new(L);</span>
<span class="lineNum">     721 </span><span class="lineCov">       1521 :   sethvalue2s(L, L-&gt;top, t);</span>
<span class="lineNum">     722 </span><span class="lineCov">       1521 :   api_incr_top(L);</span>
<span class="lineNum">     723 </span><span class="lineCov">       1521 :   if (narray &gt; 0 || nrec &gt; 0)</span>
<span class="lineNum">     724 </span><span class="lineCov">       1251 :     luaH_resize(L, t, narray, nrec);</span>
<span class="lineNum">     725 </span><span class="lineCov">       1521 :   luaC_checkGC(L);</span>
<span class="lineNum">     726 </span>            :   lua_unlock(L);
<span class="lineNum">     727 </span><span class="lineCov">       1521 : }</span>
<span class="lineNum">     728 </span>            : 
<span class="lineNum">     729 </span>            : 
<span class="lineNum">     730 </span><span class="lineCov">       6439 : LUA_API int lua_getmetatable (lua_State *L, int objindex) {</span>
<span class="lineNum">     731 </span>            :   const TValue *obj;
<span class="lineNum">     732 </span>            :   Table *mt;
<span class="lineNum">     733 </span><span class="lineCov">       6439 :   int res = 0;</span>
<span class="lineNum">     734 </span>            :   lua_lock(L);
<span class="lineNum">     735 </span><span class="lineCov">       6439 :   obj = index2value(L, objindex);</span>
<span class="lineNum">     736 </span><span class="lineCov">       6439 :   switch (ttype(obj)) {</span>
<span class="lineNum">     737 </span><span class="lineCov">        166 :     case LUA_TTABLE:</span>
<span class="lineNum">     738 </span><span class="lineCov">        166 :       mt = hvalue(obj)-&gt;metatable;</span>
<span class="lineNum">     739 </span><span class="lineCov">        166 :       break;</span>
<span class="lineNum">     740 </span><span class="lineCov">       1357 :     case LUA_TUSERDATA:</span>
<span class="lineNum">     741 </span><span class="lineCov">       1357 :       mt = uvalue(obj)-&gt;metatable;</span>
<span class="lineNum">     742 </span><span class="lineCov">       1357 :       break;</span>
<span class="lineNum">     743 </span><span class="lineCov">       4916 :     default:</span>
<span class="lineNum">     744 </span><span class="lineCov">       4916 :       mt = G(L)-&gt;mt[ttype(obj)];</span>
<span class="lineNum">     745 </span><span class="lineCov">       4916 :       break;</span>
<span class="lineNum">     746 </span>            :   }
<span class="lineNum">     747 </span><span class="lineCov">       6439 :   if (mt != NULL) {</span>
<span class="lineNum">     748 </span><span class="lineCov">       4197 :     sethvalue2s(L, L-&gt;top, mt);</span>
<span class="lineNum">     749 </span><span class="lineCov">       4197 :     api_incr_top(L);</span>
<span class="lineNum">     750 </span><span class="lineCov">       4197 :     res = 1;</span>
<span class="lineNum">     751 </span>            :   }
<span class="lineNum">     752 </span>            :   lua_unlock(L);
<span class="lineNum">     753 </span><span class="lineCov">       6439 :   return res;</span>
<span class="lineNum">     754 </span>            : }
<span class="lineNum">     755 </span>            : 
<span class="lineNum">     756 </span>            : 
<span class="lineNum">     757 </span><span class="lineCov">          1 : LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) {</span>
<span class="lineNum">     758 </span>            :   TValue *o;
<span class="lineNum">     759 </span>            :   int t;
<span class="lineNum">     760 </span>            :   lua_lock(L);
<span class="lineNum">     761 </span><span class="lineCov">          1 :   o = index2value(L, idx);</span>
<span class="lineNum">     762 </span>            :   api_check(L, ttisfulluserdata(o), &quot;full userdata expected&quot;);
<span class="lineNum">     763 </span><span class="lineCov">          1 :   if (n &lt;= 0 || n &gt; uvalue(o)-&gt;nuvalue) {</span>
<span class="lineNum">     764 </span><span class="lineCov">          1 :     setnilvalue(s2v(L-&gt;top));</span>
<span class="lineNum">     765 </span><span class="lineCov">          1 :     t = LUA_TNONE;</span>
<span class="lineNum">     766 </span>            :   }
<span class="lineNum">     767 </span>            :   else {
<span class="lineNum">     768 </span><span class="lineNoCov">          0 :     setobj2s(L, L-&gt;top, &amp;uvalue(o)-&gt;uv[n - 1].uv);</span>
<span class="lineNum">     769 </span><span class="lineNoCov">          0 :     t = ttype(s2v(L-&gt;top));</span>
<span class="lineNum">     770 </span>            :   }
<span class="lineNum">     771 </span><span class="lineCov">          1 :   api_incr_top(L);</span>
<span class="lineNum">     772 </span>            :   lua_unlock(L);
<span class="lineNum">     773 </span><span class="lineCov">          1 :   return t;</span>
<span class="lineNum">     774 </span>            : }
<span class="lineNum">     775 </span>            : 
<span class="lineNum">     776 </span>            : 
<span class="lineNum">     777 </span>            : /*
<span class="lineNum">     778 </span>            : ** set functions (stack -&gt; Lua)
<span class="lineNum">     779 </span>            : */
<span class="lineNum">     780 </span>            : 
<span class="lineNum">     781 </span>            : /*
<span class="lineNum">     782 </span>            : ** t[k] = value at the top of the stack (where 'k' is a string)
<span class="lineNum">     783 </span>            : */
<span class="lineNum">     784 </span><span class="lineCov">      18988 : static void auxsetstr (lua_State *L, const TValue *t, const char *k) {</span>
<span class="lineNum">     785 </span>            :   const TValue *slot;
<span class="lineNum">     786 </span><span class="lineCov">      18988 :   TString *str = luaS_new(L, k);</span>
<span class="lineNum">     787 </span>            :   api_checknelems(L, 1);
<span class="lineNum">     788 </span><span class="lineCov">      18988 :   if (luaV_fastget(L, t, str, slot, luaH_getstr)) {</span>
<span class="lineNum">     789 </span><span class="lineCov">       1435 :     luaV_finishfastset(L, t, slot, s2v(L-&gt;top - 1));</span>
<span class="lineNum">     790 </span><span class="lineCov">       1435 :     L-&gt;top--;  /* pop value */</span>
<span class="lineNum">     791 </span>            :   }
<span class="lineNum">     792 </span>            :   else {
<span class="lineNum">     793 </span><span class="lineCov">      17553 :     setsvalue2s(L, L-&gt;top, str);  /* push 'str' (to make it a TValue) */</span>
<span class="lineNum">     794 </span><span class="lineCov">      17553 :     api_incr_top(L);</span>
<span class="lineNum">     795 </span><span class="lineCov">      17553 :     luaV_finishset(L, t, s2v(L-&gt;top - 1), s2v(L-&gt;top - 2), slot);</span>
<span class="lineNum">     796 </span><span class="lineCov">      17553 :     L-&gt;top -= 2;  /* pop value and key */</span>
<span class="lineNum">     797 </span>            :   }
<span class="lineNum">     798 </span>            :   lua_unlock(L);  /* lock done by caller */
<span class="lineNum">     799 </span><span class="lineCov">      18988 : }</span>
<span class="lineNum">     800 </span>            : 
<span class="lineNum">     801 </span>            : 
<span class="lineNum">     802 </span><span class="lineCov">       1030 : LUA_API void lua_setglobal (lua_State *L, const char *name) {</span>
<span class="lineNum">     803 </span><span class="lineCov">       1030 :   Table *reg = hvalue(&amp;G(L)-&gt;l_registry);</span>
<span class="lineNum">     804 </span>            :   lua_lock(L);  /* unlock done in 'auxsetstr' */
<span class="lineNum">     805 </span><span class="lineCov">       1030 :   auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);</span>
<span class="lineNum">     806 </span><span class="lineCov">       1030 : }</span>
<span class="lineNum">     807 </span>            : 
<span class="lineNum">     808 </span>            : 
<span class="lineNum">     809 </span><span class="lineNoCov">          0 : LUA_API void lua_settable (lua_State *L, int idx) {</span>
<span class="lineNum">     810 </span>            :   TValue *t;
<span class="lineNum">     811 </span>            :   const TValue *slot;
<span class="lineNum">     812 </span>            :   lua_lock(L);
<span class="lineNum">     813 </span>            :   api_checknelems(L, 2);
<span class="lineNum">     814 </span><span class="lineNoCov">          0 :   t = index2value(L, idx);</span>
<span class="lineNum">     815 </span><span class="lineNoCov">          0 :   if (luaV_fastget(L, t, s2v(L-&gt;top - 2), slot, luaH_get)) {</span>
<span class="lineNum">     816 </span><span class="lineNoCov">          0 :     luaV_finishfastset(L, t, slot, s2v(L-&gt;top - 1));</span>
<span class="lineNum">     817 </span>            :   }
<span class="lineNum">     818 </span>            :   else
<span class="lineNum">     819 </span><span class="lineNoCov">          0 :     luaV_finishset(L, t, s2v(L-&gt;top - 2), s2v(L-&gt;top - 1), slot);</span>
<span class="lineNum">     820 </span><span class="lineNoCov">          0 :   L-&gt;top -= 2;  /* pop index and value */</span>
<span class="lineNum">     821 </span>            :   lua_unlock(L);
<span class="lineNum">     822 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">     823 </span>            : 
<span class="lineNum">     824 </span>            : 
<span class="lineNum">     825 </span><span class="lineCov">      17958 : LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {</span>
<span class="lineNum">     826 </span>            :   lua_lock(L);  /* unlock done in 'auxsetstr' */
<span class="lineNum">     827 </span><span class="lineCov">      17958 :   auxsetstr(L, index2value(L, idx), k);</span>
<span class="lineNum">     828 </span><span class="lineCov">      17958 : }</span>
<span class="lineNum">     829 </span>            : 
<span class="lineNum">     830 </span>            : 
<span class="lineNum">     831 </span><span class="lineCov">      86127 : LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {</span>
<span class="lineNum">     832 </span>            :   TValue *t;
<span class="lineNum">     833 </span>            :   const TValue *slot;
<span class="lineNum">     834 </span>            :   lua_lock(L);
<span class="lineNum">     835 </span>            :   api_checknelems(L, 1);
<span class="lineNum">     836 </span><span class="lineCov">      86127 :   t = index2value(L, idx);</span>
<span class="lineNum">     837 </span><span class="lineCov">      86127 :   if (luaV_fastgeti(L, t, n, slot)) {</span>
<span class="lineNum">     838 </span><span class="lineCov">      86062 :     luaV_finishfastset(L, t, slot, s2v(L-&gt;top - 1));</span>
<span class="lineNum">     839 </span>            :   }
<span class="lineNum">     840 </span>            :   else {
<span class="lineNum">     841 </span>            :     TValue aux;
<span class="lineNum">     842 </span><span class="lineCov">         65 :     setivalue(&amp;aux, n);</span>
<span class="lineNum">     843 </span><span class="lineCov">         65 :     luaV_finishset(L, t, &amp;aux, s2v(L-&gt;top - 1), slot);</span>
<span class="lineNum">     844 </span>            :   }
<span class="lineNum">     845 </span><span class="lineCov">      86127 :   L-&gt;top--;  /* pop value */</span>
<span class="lineNum">     846 </span>            :   lua_unlock(L);
<span class="lineNum">     847 </span><span class="lineCov">      86127 : }</span>
<span class="lineNum">     848 </span>            : 
<span class="lineNum">     849 </span>            : 
<span class="lineNum">     850 </span><span class="lineCov">          5 : LUA_API void lua_rawset (lua_State *L, int idx) {</span>
<span class="lineNum">     851 </span>            :   Table *t;
<span class="lineNum">     852 </span>            :   TValue *slot;
<span class="lineNum">     853 </span>            :   lua_lock(L);
<span class="lineNum">     854 </span>            :   api_checknelems(L, 2);
<span class="lineNum">     855 </span><span class="lineCov">          5 :   t = gettable(L, idx);</span>
<span class="lineNum">     856 </span><span class="lineCov">          5 :   slot = luaH_set(L, t, s2v(L-&gt;top - 2));</span>
<span class="lineNum">     857 </span><span class="lineCov">          4 :   setobj2t(L, slot, s2v(L-&gt;top - 1));</span>
<span class="lineNum">     858 </span><span class="lineCov">          4 :   invalidateTMcache(t);</span>
<span class="lineNum">     859 </span><span class="lineCov">          4 :   luaC_barrierback(L, obj2gco(t), s2v(L-&gt;top - 1));</span>
<span class="lineNum">     860 </span><span class="lineCov">          4 :   L-&gt;top -= 2;</span>
<span class="lineNum">     861 </span>            :   lua_unlock(L);
<span class="lineNum">     862 </span><span class="lineCov">          4 : }</span>
<span class="lineNum">     863 </span>            : 
<span class="lineNum">     864 </span>            : 
<span class="lineNum">     865 </span><span class="lineCov">        781 : LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {</span>
<span class="lineNum">     866 </span>            :   Table *t;
<span class="lineNum">     867 </span>            :   lua_lock(L);
<span class="lineNum">     868 </span>            :   api_checknelems(L, 1);
<span class="lineNum">     869 </span><span class="lineCov">        781 :   t = gettable(L, idx);</span>
<span class="lineNum">     870 </span><span class="lineCov">        781 :   luaH_setint(L, t, n, s2v(L-&gt;top - 1));</span>
<span class="lineNum">     871 </span><span class="lineCov">        781 :   luaC_barrierback(L, obj2gco(t), s2v(L-&gt;top - 1));</span>
<span class="lineNum">     872 </span><span class="lineCov">        781 :   L-&gt;top--;</span>
<span class="lineNum">     873 </span>            :   lua_unlock(L);
<span class="lineNum">     874 </span><span class="lineCov">        781 : }</span>
<span class="lineNum">     875 </span>            : 
<span class="lineNum">     876 </span>            : 
<span class="lineNum">     877 </span><span class="lineCov">         90 : LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {</span>
<span class="lineNum">     878 </span>            :   Table *t;
<span class="lineNum">     879 </span>            :   TValue k, *slot;
<span class="lineNum">     880 </span>            :   lua_lock(L);
<span class="lineNum">     881 </span>            :   api_checknelems(L, 1);
<span class="lineNum">     882 </span><span class="lineCov">         90 :   t = gettable(L, idx);</span>
<span class="lineNum">     883 </span><span class="lineCov">         90 :   setpvalue(&amp;k, cast_voidp(p));</span>
<span class="lineNum">     884 </span><span class="lineCov">         90 :   slot = luaH_set(L, t, &amp;k);</span>
<span class="lineNum">     885 </span><span class="lineCov">         90 :   setobj2t(L, slot, s2v(L-&gt;top - 1));</span>
<span class="lineNum">     886 </span><span class="lineCov">         90 :   luaC_barrierback(L, obj2gco(t), s2v(L-&gt;top - 1));</span>
<span class="lineNum">     887 </span><span class="lineCov">         90 :   L-&gt;top--;</span>
<span class="lineNum">     888 </span>            :   lua_unlock(L);
<span class="lineNum">     889 </span><span class="lineCov">         90 : }</span>
<span class="lineNum">     890 </span>            : 
<span class="lineNum">     891 </span>            : 
<span class="lineNum">     892 </span><span class="lineCov">        667 : LUA_API int lua_setmetatable (lua_State *L, int objindex) {</span>
<span class="lineNum">     893 </span>            :   TValue *obj;
<span class="lineNum">     894 </span>            :   Table *mt;
<span class="lineNum">     895 </span>            :   lua_lock(L);
<span class="lineNum">     896 </span>            :   api_checknelems(L, 1);
<span class="lineNum">     897 </span><span class="lineCov">        667 :   obj = index2value(L, objindex);</span>
<span class="lineNum">     898 </span><span class="lineCov">        667 :   if (ttisnil(s2v(L-&gt;top - 1)))</span>
<span class="lineNum">     899 </span><span class="lineCov">          1 :     mt = NULL;</span>
<span class="lineNum">     900 </span>            :   else {
<span class="lineNum">     901 </span>            :     api_check(L, ttistable(s2v(L-&gt;top - 1)), &quot;table expected&quot;);
<span class="lineNum">     902 </span><span class="lineCov">        666 :     mt = hvalue(s2v(L-&gt;top - 1));</span>
<span class="lineNum">     903 </span>            :   }
<span class="lineNum">     904 </span><span class="lineCov">        667 :   switch (ttype(obj)) {</span>
<span class="lineNum">     905 </span><span class="lineCov">        186 :     case LUA_TTABLE: {</span>
<span class="lineNum">     906 </span><span class="lineCov">        186 :       hvalue(obj)-&gt;metatable = mt;</span>
<span class="lineNum">     907 </span><span class="lineCov">        186 :       if (mt) {</span>
<span class="lineNum">     908 </span><span class="lineCov">        185 :         luaC_objbarrier(L, gcvalue(obj), mt);</span>
<span class="lineNum">     909 </span><span class="lineCov">        185 :         luaC_checkfinalizer(L, gcvalue(obj), mt);</span>
<span class="lineNum">     910 </span>            :       }
<span class="lineNum">     911 </span><span class="lineCov">        186 :       break;</span>
<span class="lineNum">     912 </span>            :     }
<span class="lineNum">     913 </span><span class="lineCov">        390 :     case LUA_TUSERDATA: {</span>
<span class="lineNum">     914 </span><span class="lineCov">        390 :       uvalue(obj)-&gt;metatable = mt;</span>
<span class="lineNum">     915 </span><span class="lineCov">        390 :       if (mt) {</span>
<span class="lineNum">     916 </span><span class="lineCov">        390 :         luaC_objbarrier(L, uvalue(obj), mt);</span>
<span class="lineNum">     917 </span><span class="lineCov">        390 :         luaC_checkfinalizer(L, gcvalue(obj), mt);</span>
<span class="lineNum">     918 </span>            :       }
<span class="lineNum">     919 </span><span class="lineCov">        390 :       break;</span>
<span class="lineNum">     920 </span>            :     }
<span class="lineNum">     921 </span><span class="lineCov">         91 :     default: {</span>
<span class="lineNum">     922 </span><span class="lineCov">         91 :       G(L)-&gt;mt[ttype(obj)] = mt;</span>
<span class="lineNum">     923 </span><span class="lineCov">         91 :       break;</span>
<span class="lineNum">     924 </span>            :     }
<span class="lineNum">     925 </span>            :   }
<span class="lineNum">     926 </span><span class="lineCov">        667 :   L-&gt;top--;</span>
<span class="lineNum">     927 </span>            :   lua_unlock(L);
<span class="lineNum">     928 </span><span class="lineCov">        667 :   return 1;</span>
<span class="lineNum">     929 </span>            : }
<span class="lineNum">     930 </span>            : 
<span class="lineNum">     931 </span>            : 
<span class="lineNum">     932 </span><span class="lineCov">          1 : LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) {</span>
<span class="lineNum">     933 </span>            :   TValue *o;
<span class="lineNum">     934 </span>            :   int res;
<span class="lineNum">     935 </span>            :   lua_lock(L);
<span class="lineNum">     936 </span>            :   api_checknelems(L, 1);
<span class="lineNum">     937 </span><span class="lineCov">          1 :   o = index2value(L, idx);</span>
<span class="lineNum">     938 </span>            :   api_check(L, ttisfulluserdata(o), &quot;full userdata expected&quot;);
<span class="lineNum">     939 </span><span class="lineCov">          1 :   if (!(cast_uint(n) - 1u &lt; cast_uint(uvalue(o)-&gt;nuvalue)))</span>
<span class="lineNum">     940 </span><span class="lineCov">          1 :     res = 0;  /* 'n' not in [1, uvalue(o)-&gt;nuvalue] */</span>
<span class="lineNum">     941 </span>            :   else {
<span class="lineNum">     942 </span><span class="lineNoCov">          0 :     setobj(L, &amp;uvalue(o)-&gt;uv[n - 1].uv, s2v(L-&gt;top - 1));</span>
<span class="lineNum">     943 </span><span class="lineNoCov">          0 :     luaC_barrierback(L, gcvalue(o), s2v(L-&gt;top - 1));</span>
<span class="lineNum">     944 </span><span class="lineNoCov">          0 :     res = 1;</span>
<span class="lineNum">     945 </span>            :   }
<span class="lineNum">     946 </span><span class="lineCov">          1 :   L-&gt;top--;</span>
<span class="lineNum">     947 </span>            :   lua_unlock(L);
<span class="lineNum">     948 </span><span class="lineCov">          1 :   return res;</span>
<span class="lineNum">     949 </span>            : }
<span class="lineNum">     950 </span>            : 
<span class="lineNum">     951 </span>            : 
<span class="lineNum">     952 </span>            : /*
<span class="lineNum">     953 </span>            : ** 'load' and 'call' functions (run Lua code)
<span class="lineNum">     954 </span>            : */
<span class="lineNum">     955 </span>            : 
<span class="lineNum">     956 </span>            : 
<span class="lineNum">     957 </span>            : #define checkresults(L,na,nr) \
<span class="lineNum">     958 </span>            :      api_check(L, (nr) == LUA_MULTRET || (L-&gt;ci-&gt;top - L-&gt;top &gt;= (nr) - (na)), \
<span class="lineNum">     959 </span>            :         &quot;results from function overflow current stack size&quot;)
<span class="lineNum">     960 </span>            : 
<span class="lineNum">     961 </span>            : 
<span class="lineNum">     962 </span><span class="lineCov">       1660 : LUA_API void lua_callk (lua_State *L, int nargs, int nresults,</span>
<span class="lineNum">     963 </span>            :                         lua_KContext ctx, lua_KFunction k) {
<span class="lineNum">     964 </span>            :   StkId func;
<span class="lineNum">     965 </span>            :   lua_lock(L);
<span class="lineNum">     966 </span>            :   api_check(L, k == NULL || !isLua(L-&gt;ci),
<span class="lineNum">     967 </span>            :     &quot;cannot use continuations inside hooks&quot;);
<span class="lineNum">     968 </span>            :   api_checknelems(L, nargs+1);
<span class="lineNum">     969 </span>            :   api_check(L, L-&gt;status == LUA_OK, &quot;cannot do calls on non-normal thread&quot;);
<span class="lineNum">     970 </span>            :   checkresults(L, nargs, nresults);
<span class="lineNum">     971 </span><span class="lineCov">       1660 :   func = L-&gt;top - (nargs+1);</span>
<span class="lineNum">     972 </span><span class="lineCov">       1660 :   if (k != NULL &amp;&amp; yieldable(L)) {  /* need to prepare continuation? */</span>
<span class="lineNum">     973 </span><span class="lineNoCov">          0 :     L-&gt;ci-&gt;u.c.k = k;  /* save continuation */</span>
<span class="lineNum">     974 </span><span class="lineNoCov">          0 :     L-&gt;ci-&gt;u.c.ctx = ctx;  /* save context */</span>
<span class="lineNum">     975 </span><span class="lineNoCov">          0 :     luaD_call(L, func, nresults);  /* do the call */</span>
<span class="lineNum">     976 </span>            :   }
<span class="lineNum">     977 </span>            :   else  /* no continuation or no yieldable */
<span class="lineNum">     978 </span><span class="lineCov">       1660 :     luaD_callnoyield(L, func, nresults);  /* just do the call */</span>
<span class="lineNum">     979 </span><span class="lineCov">       1658 :   adjustresults(L, nresults);</span>
<span class="lineNum">     980 </span>            :   lua_unlock(L);
<span class="lineNum">     981 </span><span class="lineCov">       1658 : }</span>
<span class="lineNum">     982 </span>            : 
<span class="lineNum">     983 </span>            : 
<span class="lineNum">     984 </span>            : 
<span class="lineNum">     985 </span>            : /*
<span class="lineNum">     986 </span>            : ** Execute a protected call.
<span class="lineNum">     987 </span>            : */
<span class="lineNum">     988 </span>            : struct CallS {  /* data to 'f_call' */
<span class="lineNum">     989 </span>            :   StkId func;
<span class="lineNum">     990 </span>            :   int nresults;
<span class="lineNum">     991 </span>            : };
<span class="lineNum">     992 </span>            : 
<span class="lineNum">     993 </span>            : 
<span class="lineNum">     994 </span><span class="lineCov">        979 : static void f_call (lua_State *L, void *ud) {</span>
<span class="lineNum">     995 </span><span class="lineCov">        979 :   struct CallS *c = cast(struct CallS *, ud);</span>
<span class="lineNum">     996 </span><span class="lineCov">        979 :   luaD_callnoyield(L, c-&gt;func, c-&gt;nresults);</span>
<span class="lineNum">     997 </span><span class="lineCov">        479 : }</span>
<span class="lineNum">     998 </span>            : 
<span class="lineNum">     999 </span>            : 
<span class="lineNum">    1000 </span>            : 
<span class="lineNum">    1001 </span><span class="lineCov">        981 : LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,</span>
<span class="lineNum">    1002 </span>            :                         lua_KContext ctx, lua_KFunction k) {
<span class="lineNum">    1003 </span>            :   struct CallS c;
<span class="lineNum">    1004 </span>            :   int status;
<span class="lineNum">    1005 </span>            :   ptrdiff_t func;
<span class="lineNum">    1006 </span>            :   lua_lock(L);
<span class="lineNum">    1007 </span>            :   api_check(L, k == NULL || !isLua(L-&gt;ci),
<span class="lineNum">    1008 </span>            :     &quot;cannot use continuations inside hooks&quot;);
<span class="lineNum">    1009 </span>            :   api_checknelems(L, nargs+1);
<span class="lineNum">    1010 </span>            :   api_check(L, L-&gt;status == LUA_OK, &quot;cannot do calls on non-normal thread&quot;);
<span class="lineNum">    1011 </span>            :   checkresults(L, nargs, nresults);
<span class="lineNum">    1012 </span><span class="lineCov">        981 :   if (errfunc == 0)</span>
<span class="lineNum">    1013 </span><span class="lineCov">        747 :     func = 0;</span>
<span class="lineNum">    1014 </span>            :   else {
<span class="lineNum">    1015 </span><span class="lineCov">        234 :     StkId o = index2stack(L, errfunc);</span>
<span class="lineNum">    1016 </span>            :     api_check(L, ttisfunction(s2v(o)), &quot;error handler must be a function&quot;);
<span class="lineNum">    1017 </span><span class="lineCov">        234 :     func = savestack(L, o);</span>
<span class="lineNum">    1018 </span>            :   }
<span class="lineNum">    1019 </span><span class="lineCov">        981 :   c.func = L-&gt;top - (nargs+1);  /* function to be called */</span>
<span class="lineNum">    1020 </span><span class="lineCov">        981 :   if (k == NULL || !yieldable(L)) {  /* no continuation or no yieldable? */</span>
<span class="lineNum">    1021 </span><span class="lineCov">        979 :     c.nresults = nresults;  /* do a 'conventional' protected call */</span>
<span class="lineNum">    1022 </span><span class="lineCov">        979 :     status = luaD_pcall(L, f_call, &amp;c, savestack(L, c.func), func);</span>
<span class="lineNum">    1023 </span>            :   }
<span class="lineNum">    1024 </span>            :   else {  /* prepare continuation (call is already protected by 'resume') */
<span class="lineNum">    1025 </span><span class="lineCov">          2 :     CallInfo *ci = L-&gt;ci;</span>
<span class="lineNum">    1026 </span><span class="lineCov">          2 :     ci-&gt;u.c.k = k;  /* save continuation */</span>
<span class="lineNum">    1027 </span><span class="lineCov">          2 :     ci-&gt;u.c.ctx = ctx;  /* save context */</span>
<span class="lineNum">    1028 </span>            :     /* save information for error recovery */
<span class="lineNum">    1029 </span><span class="lineCov">          2 :     ci-&gt;u2.funcidx = cast_int(savestack(L, c.func));</span>
<span class="lineNum">    1030 </span><span class="lineCov">          2 :     ci-&gt;u.c.old_errfunc = L-&gt;errfunc;</span>
<span class="lineNum">    1031 </span><span class="lineCov">          2 :     L-&gt;errfunc = func;</span>
<span class="lineNum">    1032 </span><span class="lineCov">          2 :     setoah(ci-&gt;callstatus, L-&gt;allowhook);  /* save value of 'allowhook' */</span>
<span class="lineNum">    1033 </span><span class="lineCov">          2 :     ci-&gt;callstatus |= CIST_YPCALL;  /* function can do error recovery */</span>
<span class="lineNum">    1034 </span><span class="lineCov">          2 :     luaD_call(L, c.func, nresults);  /* do the call */</span>
<span class="lineNum">    1035 </span><span class="lineNoCov">          0 :     ci-&gt;callstatus &amp;= ~CIST_YPCALL;</span>
<span class="lineNum">    1036 </span><span class="lineNoCov">          0 :     L-&gt;errfunc = ci-&gt;u.c.old_errfunc;</span>
<span class="lineNum">    1037 </span><span class="lineNoCov">          0 :     status = LUA_OK;  /* if it is here, there were no errors */</span>
<span class="lineNum">    1038 </span>            :   }
<span class="lineNum">    1039 </span><span class="lineCov">        954 :   adjustresults(L, nresults);</span>
<span class="lineNum">    1040 </span>            :   lua_unlock(L);
<span class="lineNum">    1041 </span><span class="lineCov">        954 :   return status;</span>
<span class="lineNum">    1042 </span>            : }
<span class="lineNum">    1043 </span>            : 
<span class="lineNum">    1044 </span>            : 
<span class="lineNum">    1045 </span><span class="lineCov">        528 : LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,</span>
<span class="lineNum">    1046 </span>            :                       const char *chunkname, const char *mode) {
<span class="lineNum">    1047 </span>            :   ZIO z;
<span class="lineNum">    1048 </span>            :   int status;
<span class="lineNum">    1049 </span>            :   lua_lock(L);
<span class="lineNum">    1050 </span><span class="lineCov">        528 :   if (!chunkname) chunkname = &quot;?&quot;;</span>
<span class="lineNum">    1051 </span><span class="lineCov">        528 :   luaZ_init(L, &amp;z, reader, data);</span>
<span class="lineNum">    1052 </span><span class="lineCov">        528 :   status = luaD_protectedparser(L, &amp;z, chunkname, mode);</span>
<span class="lineNum">    1053 </span><span class="lineCov">        528 :   if (status == LUA_OK) {  /* no errors? */</span>
<span class="lineNum">    1054 </span><span class="lineCov">        476 :     LClosure *f = clLvalue(s2v(L-&gt;top - 1));  /* get newly created function */</span>
<span class="lineNum">    1055 </span><span class="lineCov">        476 :     if (f-&gt;nupvalues &gt;= 1) {  /* does it have an upvalue? */</span>
<span class="lineNum">    1056 </span>            :       /* get global table from registry */
<span class="lineNum">    1057 </span><span class="lineCov">        476 :       Table *reg = hvalue(&amp;G(L)-&gt;l_registry);</span>
<span class="lineNum">    1058 </span><span class="lineCov">        476 :       const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);</span>
<span class="lineNum">    1059 </span>            :       /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
<span class="lineNum">    1060 </span><span class="lineCov">        476 :       setobj(L, f-&gt;upvals[0]-&gt;v, gt);</span>
<span class="lineNum">    1061 </span><span class="lineCov">        476 :       luaC_barrier(L, f-&gt;upvals[0], gt);</span>
<span class="lineNum">    1062 </span>            :     }
<span class="lineNum">    1063 </span>            :   }
<span class="lineNum">    1064 </span>            :   lua_unlock(L);
<span class="lineNum">    1065 </span><span class="lineCov">        528 :   return status;</span>
<span class="lineNum">    1066 </span>            : }
<span class="lineNum">    1067 </span>            : 
<span class="lineNum">    1068 </span>            : 
<span class="lineNum">    1069 </span><span class="lineCov">          2 : LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {</span>
<span class="lineNum">    1070 </span>            :   int status;
<span class="lineNum">    1071 </span>            :   TValue *o;
<span class="lineNum">    1072 </span>            :   lua_lock(L);
<span class="lineNum">    1073 </span>            :   api_checknelems(L, 1);
<span class="lineNum">    1074 </span><span class="lineCov">          2 :   o = s2v(L-&gt;top - 1);</span>
<span class="lineNum">    1075 </span><span class="lineCov">          2 :   if (isLfunction(o))</span>
<span class="lineNum">    1076 </span><span class="lineCov">          1 :     status = luaU_dump(L, getproto(o), writer, data, strip);</span>
<span class="lineNum">    1077 </span>            :   else
<span class="lineNum">    1078 </span><span class="lineCov">          1 :     status = 1;</span>
<span class="lineNum">    1079 </span>            :   lua_unlock(L);
<span class="lineNum">    1080 </span><span class="lineCov">          2 :   return status;</span>
<span class="lineNum">    1081 </span>            : }
<span class="lineNum">    1082 </span>            : 
<span class="lineNum">    1083 </span>            : 
<span class="lineNum">    1084 </span><span class="lineCov">          7 : LUA_API int lua_status (lua_State *L) {</span>
<span class="lineNum">    1085 </span><span class="lineCov">          7 :   return L-&gt;status;</span>
<span class="lineNum">    1086 </span>            : }
<span class="lineNum">    1087 </span>            : 
<span class="lineNum">    1088 </span>            : 
<span class="lineNum">    1089 </span>            : /*
<span class="lineNum">    1090 </span>            : ** Garbage-collection function
<span class="lineNum">    1091 </span>            : */
<span class="lineNum">    1092 </span><span class="lineCov">        106 : LUA_API int lua_gc (lua_State *L, int what, ...) {</span>
<span class="lineNum">    1093 </span>            :   va_list argp;
<span class="lineNum">    1094 </span><span class="lineCov">        106 :   int res = 0;</span>
<span class="lineNum">    1095 </span><span class="lineCov">        106 :   global_State *g = G(L);</span>
<span class="lineNum">    1096 </span>            :   lua_lock(L);
<span class="lineNum">    1097 </span><span class="lineCov">        106 :   va_start(argp, what);</span>
<span class="lineNum">    1098 </span><span class="lineCov">        106 :   switch (what) {</span>
<span class="lineNum">    1099 </span><span class="lineCov">          1 :     case LUA_GCSTOP: {</span>
<span class="lineNum">    1100 </span><span class="lineCov">          1 :       g-&gt;gcrunning = 0;</span>
<span class="lineNum">    1101 </span><span class="lineCov">          1 :       break;</span>
<span class="lineNum">    1102 </span>            :     }
<span class="lineNum">    1103 </span><span class="lineCov">          1 :     case LUA_GCRESTART: {</span>
<span class="lineNum">    1104 </span><span class="lineCov">          1 :       luaE_setdebt(g, 0);</span>
<span class="lineNum">    1105 </span><span class="lineCov">          1 :       g-&gt;gcrunning = 1;</span>
<span class="lineNum">    1106 </span><span class="lineCov">          1 :       break;</span>
<span class="lineNum">    1107 </span>            :     }
<span class="lineNum">    1108 </span><span class="lineCov">          2 :     case LUA_GCCOLLECT: {</span>
<span class="lineNum">    1109 </span><span class="lineCov">          2 :       luaC_fullgc(L, 0);</span>
<span class="lineNum">    1110 </span><span class="lineCov">          2 :       break;</span>
<span class="lineNum">    1111 </span>            :     }
<span class="lineNum">    1112 </span><span class="lineCov">          1 :     case LUA_GCCOUNT: {</span>
<span class="lineNum">    1113 </span>            :       /* GC values are expressed in Kbytes: #bytes/2^10 */
<span class="lineNum">    1114 </span><span class="lineCov">          1 :       res = cast_int(gettotalbytes(g) &gt;&gt; 10);</span>
<span class="lineNum">    1115 </span><span class="lineCov">          1 :       break;</span>
<span class="lineNum">    1116 </span>            :     }
<span class="lineNum">    1117 </span><span class="lineCov">          1 :     case LUA_GCCOUNTB: {</span>
<span class="lineNum">    1118 </span><span class="lineCov">          1 :       res = cast_int(gettotalbytes(g) &amp; 0x3ff);</span>
<span class="lineNum">    1119 </span><span class="lineCov">          1 :       break;</span>
<span class="lineNum">    1120 </span>            :     }
<span class="lineNum">    1121 </span><span class="lineCov">          3 :     case LUA_GCSTEP: {</span>
<span class="lineNum">    1122 </span><span class="lineCov">          3 :       int data = va_arg(argp, int);</span>
<span class="lineNum">    1123 </span><span class="lineCov">          3 :       l_mem debt = 1;  /* =1 to signal that it did an actual step */</span>
<span class="lineNum">    1124 </span><span class="lineCov">          3 :       lu_byte oldrunning = g-&gt;gcrunning;</span>
<span class="lineNum">    1125 </span><span class="lineCov">          3 :       g-&gt;gcrunning = 1;  /* allow GC to run */</span>
<span class="lineNum">    1126 </span><span class="lineCov">          3 :       if (data == 0) {</span>
<span class="lineNum">    1127 </span><span class="lineCov">          3 :         luaE_setdebt(g, 0);  /* do a basic step */</span>
<span class="lineNum">    1128 </span><span class="lineCov">          3 :         luaC_step(L);</span>
<span class="lineNum">    1129 </span>            :       }
<span class="lineNum">    1130 </span>            :       else {  /* add 'data' to total debt */
<span class="lineNum">    1131 </span><span class="lineNoCov">          0 :         debt = cast(l_mem, data) * 1024 + g-&gt;GCdebt;</span>
<span class="lineNum">    1132 </span><span class="lineNoCov">          0 :         luaE_setdebt(g, debt);</span>
<span class="lineNum">    1133 </span><span class="lineNoCov">          0 :         luaC_checkGC(L);</span>
<span class="lineNum">    1134 </span>            :       }
<span class="lineNum">    1135 </span><span class="lineCov">          3 :       g-&gt;gcrunning = oldrunning;  /* restore previous state */</span>
<span class="lineNum">    1136 </span><span class="lineCov">          3 :       if (debt &gt; 0 &amp;&amp; g-&gt;gcstate == GCSpause)  /* end of cycle? */</span>
<span class="lineNum">    1137 </span><span class="lineNoCov">          0 :         res = 1;  /* signal it */</span>
<span class="lineNum">    1138 </span><span class="lineCov">          3 :       break;</span>
<span class="lineNum">    1139 </span>            :     }
<span class="lineNum">    1140 </span><span class="lineCov">          1 :     case LUA_GCSETPAUSE: {</span>
<span class="lineNum">    1141 </span><span class="lineCov">          1 :       int data = va_arg(argp, int);</span>
<span class="lineNum">    1142 </span><span class="lineCov">          1 :       res = getgcparam(g-&gt;gcpause);</span>
<span class="lineNum">    1143 </span><span class="lineCov">          1 :       setgcparam(g-&gt;gcpause, data);</span>
<span class="lineNum">    1144 </span><span class="lineCov">          1 :       break;</span>
<span class="lineNum">    1145 </span>            :     }
<span class="lineNum">    1146 </span><span class="lineCov">          1 :     case LUA_GCSETSTEPMUL: {</span>
<span class="lineNum">    1147 </span><span class="lineCov">          1 :       int data = va_arg(argp, int);</span>
<span class="lineNum">    1148 </span><span class="lineCov">          1 :       res = getgcparam(g-&gt;gcstepmul);</span>
<span class="lineNum">    1149 </span><span class="lineCov">          1 :       setgcparam(g-&gt;gcstepmul, data);</span>
<span class="lineNum">    1150 </span><span class="lineCov">          1 :       break;</span>
<span class="lineNum">    1151 </span>            :     }
<span class="lineNum">    1152 </span><span class="lineCov">          2 :     case LUA_GCISRUNNING: {</span>
<span class="lineNum">    1153 </span><span class="lineCov">          2 :       res = g-&gt;gcrunning;</span>
<span class="lineNum">    1154 </span><span class="lineCov">          2 :       break;</span>
<span class="lineNum">    1155 </span>            :     }
<span class="lineNum">    1156 </span><span class="lineCov">         91 :     case LUA_GCGEN: {</span>
<span class="lineNum">    1157 </span><span class="lineCov">         91 :       int minormul = va_arg(argp, int);</span>
<span class="lineNum">    1158 </span><span class="lineCov">         91 :       int majormul = va_arg(argp, int);</span>
<span class="lineNum">    1159 </span><span class="lineCov">         91 :       res = isdecGCmodegen(g) ? LUA_GCGEN : LUA_GCINC;</span>
<span class="lineNum">    1160 </span><span class="lineCov">         91 :       if (minormul != 0)</span>
<span class="lineNum">    1161 </span><span class="lineNoCov">          0 :         g-&gt;genminormul = minormul;</span>
<span class="lineNum">    1162 </span><span class="lineCov">         91 :       if (majormul != 0)</span>
<span class="lineNum">    1163 </span><span class="lineNoCov">          0 :         setgcparam(g-&gt;genmajormul, majormul);</span>
<span class="lineNum">    1164 </span><span class="lineCov">         91 :       luaC_changemode(L, KGC_GEN);</span>
<span class="lineNum">    1165 </span><span class="lineCov">         91 :       break;</span>
<span class="lineNum">    1166 </span>            :     }
<span class="lineNum">    1167 </span><span class="lineCov">          2 :     case LUA_GCINC: {</span>
<span class="lineNum">    1168 </span><span class="lineCov">          2 :       int pause = va_arg(argp, int);</span>
<span class="lineNum">    1169 </span><span class="lineCov">          2 :       int stepmul = va_arg(argp, int);</span>
<span class="lineNum">    1170 </span><span class="lineCov">          2 :       int stepsize = va_arg(argp, int);</span>
<span class="lineNum">    1171 </span><span class="lineCov">          2 :       res = isdecGCmodegen(g) ? LUA_GCGEN : LUA_GCINC;</span>
<span class="lineNum">    1172 </span><span class="lineCov">          2 :       if (pause != 0)</span>
<span class="lineNum">    1173 </span><span class="lineNoCov">          0 :         setgcparam(g-&gt;gcpause, pause);</span>
<span class="lineNum">    1174 </span><span class="lineCov">          2 :       if (stepmul != 0)</span>
<span class="lineNum">    1175 </span><span class="lineNoCov">          0 :         setgcparam(g-&gt;gcstepmul, stepmul);</span>
<span class="lineNum">    1176 </span><span class="lineCov">          2 :       if (stepsize != 0)</span>
<span class="lineNum">    1177 </span><span class="lineNoCov">          0 :         g-&gt;gcstepsize = stepsize;</span>
<span class="lineNum">    1178 </span><span class="lineCov">          2 :       luaC_changemode(L, KGC_INC);</span>
<span class="lineNum">    1179 </span><span class="lineCov">          2 :       break;</span>
<span class="lineNum">    1180 </span>            :     }
<span class="lineNum">    1181 </span><span class="lineNoCov">          0 :     default: res = -1;  /* invalid option */</span>
<span class="lineNum">    1182 </span>            :   }
<span class="lineNum">    1183 </span><span class="lineCov">        106 :   va_end(argp);</span>
<span class="lineNum">    1184 </span>            :   lua_unlock(L);
<span class="lineNum">    1185 </span><span class="lineCov">        106 :   return res;</span>
<span class="lineNum">    1186 </span>            : }
<span class="lineNum">    1187 </span>            : 
<span class="lineNum">    1188 </span>            : 
<span class="lineNum">    1189 </span>            : 
<span class="lineNum">    1190 </span>            : /*
<span class="lineNum">    1191 </span>            : ** miscellaneous functions
<span class="lineNum">    1192 </span>            : */
<span class="lineNum">    1193 </span>            : 
<span class="lineNum">    1194 </span>            : 
<span class="lineNum">    1195 </span><span class="lineCov">        206 : LUA_API int lua_error (lua_State *L) {</span>
<span class="lineNum">    1196 </span>            :   lua_lock(L);
<span class="lineNum">    1197 </span>            :   api_checknelems(L, 1);
<span class="lineNum">    1198 </span><span class="lineCov">        206 :   luaG_errormsg(L);</span>
<span class="lineNum">    1199 </span>            :   /* code unreachable; will unlock when control actually leaves the kernel */
<span class="lineNum">    1200 </span>            :   return 0;  /* to avoid warnings */
<span class="lineNum">    1201 </span>            : }
<span class="lineNum">    1202 </span>            : 
<span class="lineNum">    1203 </span>            : 
<span class="lineNum">    1204 </span><span class="lineCov">       2783 : LUA_API int lua_next (lua_State *L, int idx) {</span>
<span class="lineNum">    1205 </span>            :   Table *t;
<span class="lineNum">    1206 </span>            :   int more;
<span class="lineNum">    1207 </span>            :   lua_lock(L);
<span class="lineNum">    1208 </span>            :   api_checknelems(L, 1);
<span class="lineNum">    1209 </span><span class="lineCov">       2783 :   t = gettable(L, idx);</span>
<span class="lineNum">    1210 </span><span class="lineCov">       2783 :   more = luaH_next(L, t, L-&gt;top - 1);</span>
<span class="lineNum">    1211 </span><span class="lineCov">       2782 :   if (more) {</span>
<span class="lineNum">    1212 </span><span class="lineCov">       2607 :     api_incr_top(L);</span>
<span class="lineNum">    1213 </span>            :   }
<span class="lineNum">    1214 </span>            :   else  /* no more elements */
<span class="lineNum">    1215 </span><span class="lineCov">        175 :     L-&gt;top -= 1;  /* remove key */</span>
<span class="lineNum">    1216 </span>            :   lua_unlock(L);
<span class="lineNum">    1217 </span><span class="lineCov">       2782 :   return more;</span>
<span class="lineNum">    1218 </span>            : }
<span class="lineNum">    1219 </span>            : 
<span class="lineNum">    1220 </span>            : 
<span class="lineNum">    1221 </span><span class="lineCov">          5 : LUA_API void lua_toclose (lua_State *L, int idx) {</span>
<span class="lineNum">    1222 </span>            :   int nresults;
<span class="lineNum">    1223 </span>            :   StkId o;
<span class="lineNum">    1224 </span>            :   lua_lock(L);
<span class="lineNum">    1225 </span><span class="lineCov">          5 :   o = index2stack(L, idx);</span>
<span class="lineNum">    1226 </span><span class="lineCov">          5 :   nresults = L-&gt;ci-&gt;nresults;</span>
<span class="lineNum">    1227 </span>            :   api_check(L, L-&gt;openupval == NULL || uplevel(L-&gt;openupval) &lt;= o,
<span class="lineNum">    1228 </span>            :                &quot;marked index below or equal new one&quot;);
<span class="lineNum">    1229 </span><span class="lineCov">          5 :   luaF_newtbcupval(L, o);  /* create new to-be-closed upvalue */</span>
<span class="lineNum">    1230 </span><span class="lineCov">          5 :   if (!hastocloseCfunc(nresults))  /* function not marked yet? */</span>
<span class="lineNum">    1231 </span><span class="lineCov">          5 :     L-&gt;ci-&gt;nresults = codeNresults(nresults);  /* mark it */</span>
<span class="lineNum">    1232 </span>            :   lua_assert(hastocloseCfunc(L-&gt;ci-&gt;nresults));
<span class="lineNum">    1233 </span>            :   lua_unlock(L);
<span class="lineNum">    1234 </span><span class="lineCov">          5 : }</span>
<span class="lineNum">    1235 </span>            : 
<span class="lineNum">    1236 </span>            : 
<span class="lineNum">    1237 </span><span class="lineCov">        202 : LUA_API void lua_concat (lua_State *L, int n) {</span>
<span class="lineNum">    1238 </span>            :   lua_lock(L);
<span class="lineNum">    1239 </span>            :   api_checknelems(L, n);
<span class="lineNum">    1240 </span><span class="lineCov">        202 :   if (n &gt;= 2) {</span>
<span class="lineNum">    1241 </span><span class="lineCov">        202 :     luaV_concat(L, n);</span>
<span class="lineNum">    1242 </span>            :   }
<span class="lineNum">    1243 </span><span class="lineNoCov">          0 :   else if (n == 0) {  /* push empty string */</span>
<span class="lineNum">    1244 </span><span class="lineNoCov">          0 :     setsvalue2s(L, L-&gt;top, luaS_newlstr(L, &quot;&quot;, 0));</span>
<span class="lineNum">    1245 </span><span class="lineNoCov">          0 :     api_incr_top(L);</span>
<span class="lineNum">    1246 </span>            :   }
<span class="lineNum">    1247 </span>            :   /* else n == 1; nothing to do */
<span class="lineNum">    1248 </span><span class="lineCov">        202 :   luaC_checkGC(L);</span>
<span class="lineNum">    1249 </span>            :   lua_unlock(L);
<span class="lineNum">    1250 </span><span class="lineCov">        202 : }</span>
<span class="lineNum">    1251 </span>            : 
<span class="lineNum">    1252 </span>            : 
<span class="lineNum">    1253 </span><span class="lineCov">      18104 : LUA_API void lua_len (lua_State *L, int idx) {</span>
<span class="lineNum">    1254 </span>            :   TValue *t;
<span class="lineNum">    1255 </span>            :   lua_lock(L);
<span class="lineNum">    1256 </span><span class="lineCov">      18104 :   t = index2value(L, idx);</span>
<span class="lineNum">    1257 </span><span class="lineCov">      18104 :   luaV_objlen(L, L-&gt;top, t);</span>
<span class="lineNum">    1258 </span><span class="lineCov">      18104 :   api_incr_top(L);</span>
<span class="lineNum">    1259 </span>            :   lua_unlock(L);
<span class="lineNum">    1260 </span><span class="lineCov">      18104 : }</span>
<span class="lineNum">    1261 </span>            : 
<span class="lineNum">    1262 </span>            : 
<span class="lineNum">    1263 </span><span class="lineCov">         15 : LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {</span>
<span class="lineNum">    1264 </span>            :   lua_Alloc f;
<span class="lineNum">    1265 </span>            :   lua_lock(L);
<span class="lineNum">    1266 </span><span class="lineCov">         15 :   if (ud) *ud = G(L)-&gt;ud;</span>
<span class="lineNum">    1267 </span><span class="lineCov">         15 :   f = G(L)-&gt;frealloc;</span>
<span class="lineNum">    1268 </span>            :   lua_unlock(L);
<span class="lineNum">    1269 </span><span class="lineCov">         15 :   return f;</span>
<span class="lineNum">    1270 </span>            : }
<span class="lineNum">    1271 </span>            : 
<span class="lineNum">    1272 </span>            : 
<span class="lineNum">    1273 </span><span class="lineNoCov">          0 : LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {</span>
<span class="lineNum">    1274 </span>            :   lua_lock(L);
<span class="lineNum">    1275 </span><span class="lineNoCov">          0 :   G(L)-&gt;ud = ud;</span>
<span class="lineNum">    1276 </span><span class="lineNoCov">          0 :   G(L)-&gt;frealloc = f;</span>
<span class="lineNum">    1277 </span>            :   lua_unlock(L);
<span class="lineNum">    1278 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">    1279 </span>            : 
<span class="lineNum">    1280 </span>            : 
<span class="lineNum">    1281 </span><span class="lineCov">        108 : void lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud) {</span>
<span class="lineNum">    1282 </span>            :   lua_lock(L);
<span class="lineNum">    1283 </span><span class="lineCov">        108 :   G(L)-&gt;ud_warn = ud;</span>
<span class="lineNum">    1284 </span><span class="lineCov">        108 :   G(L)-&gt;warnf = f;</span>
<span class="lineNum">    1285 </span>            :   lua_unlock(L);
<span class="lineNum">    1286 </span><span class="lineCov">        108 : }</span>
<span class="lineNum">    1287 </span>            : 
<span class="lineNum">    1288 </span>            : 
<span class="lineNum">    1289 </span><span class="lineCov">          7 : void lua_warning (lua_State *L, const char *msg, int tocont) {</span>
<span class="lineNum">    1290 </span>            :   lua_lock(L);
<span class="lineNum">    1291 </span><span class="lineCov">          7 :   luaE_warning(L, msg, tocont);</span>
<span class="lineNum">    1292 </span>            :   lua_unlock(L);
<span class="lineNum">    1293 </span><span class="lineCov">          7 : }</span>
<span class="lineNum">    1294 </span>            : 
<span class="lineNum">    1295 </span>            : 
<span class="lineNum">    1296 </span>            : 
<span class="lineNum">    1297 </span><span class="lineCov">        592 : LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) {</span>
<span class="lineNum">    1298 </span>            :   Udata *u;
<span class="lineNum">    1299 </span>            :   lua_lock(L);
<span class="lineNum">    1300 </span>            :   api_check(L, 0 &lt;= nuvalue &amp;&amp; nuvalue &lt; USHRT_MAX, &quot;invalid value&quot;);
<span class="lineNum">    1301 </span><span class="lineCov">        592 :   u = luaS_newudata(L, size, nuvalue);</span>
<span class="lineNum">    1302 </span><span class="lineCov">        592 :   setuvalue(L, s2v(L-&gt;top), u);</span>
<span class="lineNum">    1303 </span><span class="lineCov">        592 :   api_incr_top(L);</span>
<span class="lineNum">    1304 </span><span class="lineCov">        592 :   luaC_checkGC(L);</span>
<span class="lineNum">    1305 </span>            :   lua_unlock(L);
<span class="lineNum">    1306 </span><span class="lineCov">        592 :   return getudatamem(u);</span>
<span class="lineNum">    1307 </span>            : }
<span class="lineNum">    1308 </span>            : 
<span class="lineNum">    1309 </span>            : 
<span class="lineNum">    1310 </span>            : 
<span class="lineNum">    1311 </span><span class="lineCov">          9 : static const char *aux_upvalue (TValue *fi, int n, TValue **val,</span>
<span class="lineNum">    1312 </span>            :                                 GCObject **owner) {
<span class="lineNum">    1313 </span><span class="lineCov">          9 :   switch (ttypetag(fi)) {</span>
<span class="lineNum">    1314 </span><span class="lineNoCov">          0 :     case LUA_TCCL: {  /* C closure */</span>
<span class="lineNum">    1315 </span><span class="lineNoCov">          0 :       CClosure *f = clCvalue(fi);</span>
<span class="lineNum">    1316 </span><span class="lineNoCov">          0 :       if (!(cast_uint(n) - 1u &lt; cast_uint(f-&gt;nupvalues)))</span>
<span class="lineNum">    1317 </span><span class="lineNoCov">          0 :         return NULL;  /* 'n' not in [1, f-&gt;nupvalues] */</span>
<span class="lineNum">    1318 </span><span class="lineNoCov">          0 :       *val = &amp;f-&gt;upvalue[n-1];</span>
<span class="lineNum">    1319 </span><span class="lineNoCov">          0 :       if (owner) *owner = obj2gco(f);</span>
<span class="lineNum">    1320 </span><span class="lineNoCov">          0 :       return &quot;&quot;;</span>
<span class="lineNum">    1321 </span>            :     }
<span class="lineNum">    1322 </span><span class="lineCov">          9 :     case LUA_TLCL: {  /* Lua closure */</span>
<span class="lineNum">    1323 </span><span class="lineCov">          9 :       LClosure *f = clLvalue(fi);</span>
<span class="lineNum">    1324 </span>            :       TString *name;
<span class="lineNum">    1325 </span><span class="lineCov">          9 :       Proto *p = f-&gt;p;</span>
<span class="lineNum">    1326 </span><span class="lineCov">          9 :       if (!(cast_uint(n) - 1u  &lt; cast_uint(p-&gt;sizeupvalues)))</span>
<span class="lineNum">    1327 </span><span class="lineCov">          1 :         return NULL;  /* 'n' not in [1, p-&gt;sizeupvalues] */</span>
<span class="lineNum">    1328 </span><span class="lineCov">          8 :       *val = f-&gt;upvals[n-1]-&gt;v;</span>
<span class="lineNum">    1329 </span><span class="lineCov">          8 :       if (owner) *owner = obj2gco(f-&gt;upvals[n - 1]);</span>
<span class="lineNum">    1330 </span><span class="lineCov">          8 :       name = p-&gt;upvalues[n-1].name;</span>
<span class="lineNum">    1331 </span><span class="lineCov">          8 :       return (name == NULL) ? &quot;(no name)&quot; : getstr(name);</span>
<span class="lineNum">    1332 </span>            :     }
<span class="lineNum">    1333 </span><span class="lineNoCov">          0 :     default: return NULL;  /* not a closure */</span>
<span class="lineNum">    1334 </span>            :   }
<span class="lineNum">    1335 </span>            : }
<span class="lineNum">    1336 </span>            : 
<span class="lineNum">    1337 </span>            : 
<span class="lineNum">    1338 </span><span class="lineCov">          5 : LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {</span>
<span class="lineNum">    1339 </span>            :   const char *name;
<span class="lineNum">    1340 </span><span class="lineCov">          5 :   TValue *val = NULL;  /* to avoid warnings */</span>
<span class="lineNum">    1341 </span>            :   lua_lock(L);
<span class="lineNum">    1342 </span><span class="lineCov">          5 :   name = aux_upvalue(index2value(L, funcindex), n, &amp;val, NULL);</span>
<span class="lineNum">    1343 </span><span class="lineCov">          5 :   if (name) {</span>
<span class="lineNum">    1344 </span><span class="lineCov">          5 :     setobj2s(L, L-&gt;top, val);</span>
<span class="lineNum">    1345 </span><span class="lineCov">          5 :     api_incr_top(L);</span>
<span class="lineNum">    1346 </span>            :   }
<span class="lineNum">    1347 </span>            :   lua_unlock(L);
<span class="lineNum">    1348 </span><span class="lineCov">          5 :   return name;</span>
<span class="lineNum">    1349 </span>            : }
<span class="lineNum">    1350 </span>            : 
<span class="lineNum">    1351 </span>            : 
<span class="lineNum">    1352 </span><span class="lineCov">          4 : LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {</span>
<span class="lineNum">    1353 </span>            :   const char *name;
<span class="lineNum">    1354 </span><span class="lineCov">          4 :   TValue *val = NULL;  /* to avoid warnings */</span>
<span class="lineNum">    1355 </span><span class="lineCov">          4 :   GCObject *owner = NULL;  /* to avoid warnings */</span>
<span class="lineNum">    1356 </span>            :   TValue *fi;
<span class="lineNum">    1357 </span>            :   lua_lock(L);
<span class="lineNum">    1358 </span><span class="lineCov">          4 :   fi = index2value(L, funcindex);</span>
<span class="lineNum">    1359 </span>            :   api_checknelems(L, 1);
<span class="lineNum">    1360 </span><span class="lineCov">          4 :   name = aux_upvalue(fi, n, &amp;val, &amp;owner);</span>
<span class="lineNum">    1361 </span><span class="lineCov">          4 :   if (name) {</span>
<span class="lineNum">    1362 </span><span class="lineCov">          3 :     L-&gt;top--;</span>
<span class="lineNum">    1363 </span><span class="lineCov">          3 :     setobj(L, val, s2v(L-&gt;top));</span>
<span class="lineNum">    1364 </span><span class="lineCov">          3 :     luaC_barrier(L, owner, val);</span>
<span class="lineNum">    1365 </span>            :   }
<span class="lineNum">    1366 </span>            :   lua_unlock(L);
<span class="lineNum">    1367 </span><span class="lineCov">          4 :   return name;</span>
<span class="lineNum">    1368 </span>            : }
<span class="lineNum">    1369 </span>            : 
<span class="lineNum">    1370 </span>            : 
<span class="lineNum">    1371 </span><span class="lineCov">          3 : static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {</span>
<span class="lineNum">    1372 </span>            :   LClosure *f;
<span class="lineNum">    1373 </span><span class="lineCov">          3 :   TValue *fi = index2value(L, fidx);</span>
<span class="lineNum">    1374 </span>            :   api_check(L, ttisLclosure(fi), &quot;Lua function expected&quot;);
<span class="lineNum">    1375 </span><span class="lineCov">          3 :   f = clLvalue(fi);</span>
<span class="lineNum">    1376 </span>            :   api_check(L, (1 &lt;= n &amp;&amp; n &lt;= f-&gt;p-&gt;sizeupvalues), &quot;invalid upvalue index&quot;);
<span class="lineNum">    1377 </span><span class="lineCov">          3 :   if (pf) *pf = f;</span>
<span class="lineNum">    1378 </span><span class="lineCov">          3 :   return &amp;f-&gt;upvals[n - 1];  /* get its upvalue pointer */</span>
<span class="lineNum">    1379 </span>            : }
<span class="lineNum">    1380 </span>            : 
<span class="lineNum">    1381 </span>            : 
<span class="lineNum">    1382 </span><span class="lineCov">          1 : LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {</span>
<span class="lineNum">    1383 </span><span class="lineCov">          1 :   TValue *fi = index2value(L, fidx);</span>
<span class="lineNum">    1384 </span><span class="lineCov">          1 :   switch (ttypetag(fi)) {</span>
<span class="lineNum">    1385 </span><span class="lineCov">          1 :     case LUA_TLCL: {  /* lua closure */</span>
<span class="lineNum">    1386 </span><span class="lineCov">          1 :       return *getupvalref(L, fidx, n, NULL);</span>
<span class="lineNum">    1387 </span>            :     }
<span class="lineNum">    1388 </span><span class="lineNoCov">          0 :     case LUA_TCCL: {  /* C closure */</span>
<span class="lineNum">    1389 </span><span class="lineNoCov">          0 :       CClosure *f = clCvalue(fi);</span>
<span class="lineNum">    1390 </span>            :       api_check(L, 1 &lt;= n &amp;&amp; n &lt;= f-&gt;nupvalues, &quot;invalid upvalue index&quot;);
<span class="lineNum">    1391 </span><span class="lineNoCov">          0 :       return &amp;f-&gt;upvalue[n - 1];</span>
<span class="lineNum">    1392 </span>            :     }
<span class="lineNum">    1393 </span><span class="lineNoCov">          0 :     default: {</span>
<span class="lineNum">    1394 </span>            :       api_check(L, 0, &quot;closure expected&quot;);
<span class="lineNum">    1395 </span><span class="lineNoCov">          0 :       return NULL;</span>
<span class="lineNum">    1396 </span>            :     }
<span class="lineNum">    1397 </span>            :   }
<span class="lineNum">    1398 </span>            : }
<span class="lineNum">    1399 </span>            : 
<span class="lineNum">    1400 </span>            : 
<span class="lineNum">    1401 </span><span class="lineCov">          1 : LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,</span>
<span class="lineNum">    1402 </span>            :                                             int fidx2, int n2) {
<span class="lineNum">    1403 </span>            :   LClosure *f1;
<span class="lineNum">    1404 </span><span class="lineCov">          1 :   UpVal **up1 = getupvalref(L, fidx1, n1, &amp;f1);</span>
<span class="lineNum">    1405 </span><span class="lineCov">          1 :   UpVal **up2 = getupvalref(L, fidx2, n2, NULL);</span>
<span class="lineNum">    1406 </span><span class="lineCov">          1 :   *up1 = *up2;</span>
<span class="lineNum">    1407 </span><span class="lineCov">          1 :   luaC_objbarrier(L, f1, *up1);</span>
<span class="lineNum">    1408 </span><span class="lineCov">          1 : }</span>
<span class="lineNum">    1409 </span>            : 
<span class="lineNum">    1410 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
